@@ -140,7 +140,7 @@ public override void OnActionExecuting(ActionExecutingContext context)
140
140
{
141
141
elementType = TypeHelper . GetImplementedIEnumerableType ( returnType ) ;
142
142
}
143
- else if ( TypeHelper . IsGenericType ( returnType ) && returnType . GetGenericTypeDefinition ( ) == typeof ( Task < > ) )
143
+ else if ( TypeHelper . IsGenericType ( returnType ) && returnType . GetGenericTypeDefinition ( ) == typeof ( Task < > ) )
144
144
{
145
145
elementType = returnType . GetGenericArguments ( ) . First ( ) ;
146
146
}
@@ -228,46 +228,44 @@ public override void OnActionExecuted(ActionExecutedContext actionExecutedContex
228
228
{
229
229
// actionExecutedContext.Result might also indicate a status code that has not yet
230
230
// been applied to the result; make sure it's also successful.
231
- StatusCodeResult statusCodeResult = actionExecutedContext . Result as StatusCodeResult ;
232
- if ( statusCodeResult == null || IsSuccessStatusCode ( statusCodeResult . StatusCode ) )
231
+ ObjectResult responseContent = actionExecutedContext . Result as ObjectResult ;
232
+
233
+ if ( responseContent != null && ( responseContent . StatusCode == null || IsSuccessStatusCode ( responseContent . StatusCode . Value ) ) )
233
234
{
234
- ObjectResult responseContent = actionExecutedContext . Result as ObjectResult ;
235
- if ( responseContent != null )
235
+
236
+ //throw Error.Argument("actionExecutedContext", SRResources.QueryingRequiresObjectContent,
237
+ // actionExecutedContext.Result.GetType().FullName);
238
+
239
+ // Get collection from SingleResult.
240
+ IQueryable singleResultCollection = null ;
241
+ SingleResult singleResult = responseContent . Value as SingleResult ;
242
+ if ( singleResult != null )
243
+ {
244
+ // This could be a SingleResult, which has the property Queryable.
245
+ // But it could be a SingleResult() or SingleResult<T>. Sort by number of parameters
246
+ // on the property and get the one with the most parameters.
247
+ PropertyInfo propInfo = responseContent . Value . GetType ( ) . GetProperties ( )
248
+ . OrderBy ( p => p . GetIndexParameters ( ) . Count ( ) )
249
+ . Where ( p => p . Name . Equals ( "Queryable" ) )
250
+ . LastOrDefault ( ) ;
251
+
252
+ singleResultCollection = propInfo . GetValue ( singleResult ) as IQueryable ;
253
+ }
254
+
255
+ // Execution the action.
256
+ object queryResult = OnActionExecuted (
257
+ responseContent . Value ,
258
+ singleResultCollection ,
259
+ new WebApiActionDescriptor ( actionDescriptor as ControllerActionDescriptor ) ,
260
+ new WebApiRequestMessage ( request ) ,
261
+ ( elementClrType ) => GetModel ( elementClrType , request , actionDescriptor ) ,
262
+ ( queryContext ) => CreateAndValidateQueryOptions ( request , queryContext ) ,
263
+ ( statusCode ) => actionExecutedContext . Result = new StatusCodeResult ( ( int ) statusCode ) ,
264
+ ( statusCode , message , exception ) => actionExecutedContext . Result = CreateBadRequestResult ( message , exception ) ) ;
265
+
266
+ if ( queryResult != null )
236
267
{
237
- //throw Error.Argument("actionExecutedContext", SRResources.QueryingRequiresObjectContent,
238
- // actionExecutedContext.Result.GetType().FullName);
239
-
240
- // Get collection from SingleResult.
241
- IQueryable singleResultCollection = null ;
242
- SingleResult singleResult = responseContent . Value as SingleResult ;
243
- if ( singleResult != null )
244
- {
245
- // This could be a SingleResult, which has the property Queryable.
246
- // But it could be a SingleResult() or SingleResult<T>. Sort by number of parameters
247
- // on the property and get the one with the most parameters.
248
- PropertyInfo propInfo = responseContent . Value . GetType ( ) . GetProperties ( )
249
- . OrderBy ( p => p . GetIndexParameters ( ) . Count ( ) )
250
- . Where ( p => p . Name . Equals ( "Queryable" ) )
251
- . LastOrDefault ( ) ;
252
-
253
- singleResultCollection = propInfo . GetValue ( singleResult ) as IQueryable ;
254
- }
255
-
256
- // Execution the action.
257
- object queryResult = OnActionExecuted (
258
- responseContent . Value ,
259
- singleResultCollection ,
260
- new WebApiActionDescriptor ( actionDescriptor as ControllerActionDescriptor ) ,
261
- new WebApiRequestMessage ( request ) ,
262
- ( elementClrType ) => GetModel ( elementClrType , request , actionDescriptor ) ,
263
- ( queryContext ) => CreateAndValidateQueryOptions ( request , queryContext ) ,
264
- ( statusCode ) => actionExecutedContext . Result = new StatusCodeResult ( ( int ) statusCode ) ,
265
- ( statusCode , message , exception ) => actionExecutedContext . Result = CreateBadRequestResult ( message , exception ) ) ;
266
-
267
- if ( queryResult != null )
268
- {
269
- responseContent . Value = queryResult ;
270
- }
268
+ responseContent . Value = queryResult ;
271
269
}
272
270
}
273
271
}
0 commit comments