@@ -38,17 +38,33 @@ public class GenericODataController<T, TEntityId> : ODataController
3838 private ApiGeneratorConfig apiGenConfig ;
3939
4040
41+ //public GenericODataController(
42+ // IAuthorizationService authorizationService,
43+ // IGenericRespository<T, TEntityId> repository,
44+ // ApplicationDataService<GenericDbContext, AuthDbContext> dataService)
45+ //{
46+ // this.repository = repository;
47+ // this.authorizationService = authorizationService;
48+ // this.appDataService = dataService;
49+
50+ // ConfigureController();
51+ //}
52+
53+
4154 public GenericODataController (
4255 IAuthorizationService authorizationService ,
4356 IGenericRespository < T , TEntityId > repository ,
4457 ApplicationDataService < GenericDbContext , AuthDbContext > dataService ,
58+ ODataScopeService < T , TEntityId > scopeLookup ,
4559 ApiGeneratorConfig apiGenConfig )
4660 {
4761 this . repository = repository ;
4862 this . authorizationService = authorizationService ;
4963 this . appDataService = dataService ;
5064 this . apiGenConfig = apiGenConfig ;
5165
66+ this . scopeLookup = scopeLookup ;
67+
5268 ConfigureController ( ) ;
5369 }
5470 private void ConfigureController ( )
@@ -70,6 +86,13 @@ private void ConfigureController()
7086 {
7187 this . cacheOptions = cacheAttrib ;
7288 }
89+
90+ // Get RabbitMQ Settings
91+ var eventAttr = Attribute . GetCustomAttributes ( typeof ( EventAttribute ) ) ;
92+ if ( attrs . FirstOrDefault ( p => p . GetType ( ) == typeof ( EventAttribute ) ) is EventAttribute eventAttrib )
93+ {
94+ this . eventOptions = eventAttrib ;
95+ }
7396 }
7497
7598 /// <summary>
@@ -80,7 +103,7 @@ private void ConfigureController()
80103 [ ProducesErrorResponseType ( typeof ( BadRequestResult ) ) ]
81104 [ HttpGet ]
82105 [ EnableQuery (
83- AllowedQueryOptions = AllowedQueryOptions . All ,
106+ AllowedQueryOptions = AllowedQueryOptions . Search | AllowedQueryOptions . Filter ,
84107 AllowedFunctions = AllowedFunctions . All ,
85108 PageSize = 20 )
86109 ]
@@ -130,7 +153,6 @@ public async Task<IActionResult> Find(ODataQueryOptions<T> ODataOpts, TEntityId
130153 return Ok ( record ) ;
131154 }
132155
133-
134156 [ HttpPost ]
135157 public async Task < IActionResult > Create ( [ FromBody ] T record )
136158 {
@@ -144,7 +166,7 @@ public async Task<IActionResult> Create([FromBody] T record)
144166 await this . repository . SaveAsync ( ) ;
145167
146168
147- if ( eventOptions . events . HasFlag ( AMQPEvents . Created ) ) CheckAndSendEvent ( record , typeof ( T ) . Name + ".CREATED" , null ) ;
169+ if ( eventOptions != null && eventOptions . events . HasFlag ( AMQPEvents . Created ) ) CheckAndSendEvent ( record , typeof ( T ) . Name + ".CREATED" , null ) ;
148170
149171 // respond with the newly created record
150172 return CreatedAtAction ( "Find" , new
@@ -201,7 +223,7 @@ record = await baseEntity.BeforeUpdate(record, existingRecord, this.appDataServi
201223 }
202224
203225
204- if ( eventOptions . events . HasFlag ( AMQPEvents . Created ) ) CheckAndSendEvent ( record , typeof ( T ) . Name + ".UPDATED" , null ) ;
226+ if ( eventOptions != null && eventOptions . events . HasFlag ( AMQPEvents . Updated ) ) CheckAndSendEvent ( record , typeof ( T ) . Name + ".UPDATED" , existingRecord ) ;
205227
206228
207229 return Ok ( record ) ;
@@ -229,7 +251,7 @@ public async Task<IActionResult> Delete(TEntityId id)
229251
230252 this . repository . Delete ( id , this . appDataService ) ;
231253
232- if ( eventOptions . events . HasFlag ( AMQPEvents . Created ) ) CheckAndSendEvent ( existingRecord , typeof ( T ) . Name + ".DELETED" , null ) ;
254+ if ( eventOptions != null && eventOptions . events . HasFlag ( AMQPEvents . Created ) ) CheckAndSendEvent ( existingRecord , typeof ( T ) . Name + ".DELETED" , null ) ;
233255 if ( await this . repository . SaveAsync ( ) == 0 )
234256 {
235257 return BadRequest ( ) ;
@@ -243,20 +265,6 @@ public async Task<IActionResult> Delete(TEntityId id)
243265 }
244266 }
245267
246- public GenericODataController (
247- IAuthorizationService authorizationService ,
248- IGenericRespository < T , TEntityId > repository ,
249- ODataScopeService < T , TEntityId > scopeLookup ,
250- ApplicationDataService < GenericDbContext , AuthDbContext > dataService )
251- {
252- this . repository = repository ;
253- this . authorizationService = authorizationService ;
254- this . scopeLookup = scopeLookup ;
255- this . appDataService = dataService ;
256-
257- ConfigureController ( ) ;
258- }
259-
260268
261269
262270 private void CheckAndSendEvent ( T record , string Name , T oldRecord )
0 commit comments