-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
11 changed files
with
175 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/AutoQueryable.AspNet.Filter/Filters/AutoQueryableFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Net.Http.Formatting; | ||
using System.Web.Http.Filters; | ||
using AutoQueryable.Extensions; | ||
using AutoQueryable.Models; | ||
|
||
namespace AutoQueryable.AspNet.Filter.Filters | ||
{ | ||
public class AutoQueryableFilter : ActionFilterAttribute | ||
{ | ||
public string[] UnselectableProperties { get; set; } | ||
|
||
|
||
public override void OnActionExecuted(HttpActionExecutedContext context) | ||
{ | ||
var content = context.Response.Content as ObjectContent; | ||
if (content != null) | ||
{ | ||
IQueryable<object> query = content.Value as IQueryable<object>; | ||
if (query == null) throw new Exception("Unable to retreive value of IQueryable from context result."); | ||
Type entityType = query.GetType().GenericTypeArguments[0]; | ||
|
||
string queryString = context.Request.RequestUri.Query; | ||
// Work on generic type directly, for dto projection | ||
var result = query.AutoQueryable(queryString, new AutoQueryableProfile {UnselectableProperties = UnselectableProperties}); | ||
context.Response.Content = new ObjectContent(result.GetType(), result, new JsonMediaTypeFormatter()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/AutoQueryable.AspNetCore.Filter/Attributes/AutoQueryableAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using AutoQueryable.AspNetCore.Filter.Filters; | ||
using AutoQueryable.Models; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
|
||
namespace AutoQueryable.AspNetCore.Filter.Attributes | ||
{ | ||
[AttributeUsage(AttributeTargets.Method)] | ||
public class AutoQueryableAttribute : Attribute, IFilterFactory, IOrderedFilter | ||
{ | ||
public string[] UnselectableProperties { get; set; } | ||
|
||
/// <inheritdoc /> | ||
public bool IsReusable { get; set; } | ||
|
||
/// <inheritdoc /> | ||
public int Order { get; set; } | ||
|
||
public IFilterMetadata CreateInstance(IServiceProvider serviceProvider) | ||
{ | ||
if (serviceProvider == null) | ||
{ | ||
throw new ArgumentNullException(nameof(serviceProvider)); | ||
} | ||
var profile = new AutoQueryableProfile | ||
{ | ||
UnselectableProperties = UnselectableProperties | ||
}; | ||
|
||
return new AutoQueryableFilter(profile); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/AutoQueryable.AspNetCore.Filter/Filters/AutoQueryableFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using AutoQueryable.Helpers; | ||
using AutoQueryable.Models; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
|
||
namespace AutoQueryable.AspNetCore.Filter.Filters | ||
{ | ||
public class AutoQueryableFilter : ActionFilterAttribute, IActionFilter | ||
{ | ||
private readonly AutoQueryableProfile _autoQueryableProfile; | ||
|
||
public AutoQueryableFilter(AutoQueryableProfile autoQueryableProfile) | ||
{ | ||
_autoQueryableProfile = autoQueryableProfile; | ||
} | ||
public virtual void OnActionExecuting(ActionExecutingContext context) | ||
{ | ||
} | ||
|
||
public virtual void OnActionExecuted(ActionExecutedContext context) | ||
{ | ||
dynamic query = ((ObjectResult)context.Result).Value; | ||
if (query == null) throw new Exception("Unable to retreive value of IQueryable from context result."); | ||
Type entityType = query.GetType().GenericTypeArguments[0]; | ||
|
||
string queryString = context.HttpContext.Request.QueryString.HasValue ? context.HttpContext.Request.QueryString.Value : null; | ||
// Work on generic type directly, for dto projection | ||
context.Result = new OkObjectResult(QueryableHelper.GetAutoQuery(queryString, entityType, query, _autoQueryableProfile)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
using System; | ||
using AutoQueryable.Filters; | ||
using AutoQueryable.Models; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
//using System; | ||
//using AutoQueryable.Filters; | ||
//using AutoQueryable.Models; | ||
//using Microsoft.AspNetCore.Mvc.Filters; | ||
|
||
namespace AutoQueryable.Attributes | ||
{ | ||
[AttributeUsage(AttributeTargets.Method)] | ||
public class AutoQueryableAttribute : Attribute, IFilterFactory, IOrderedFilter | ||
{ | ||
public string[] UnselectableProperties { get; set; } | ||
//namespace AutoQueryable.Attributes | ||
//{ | ||
// [AttributeUsage(AttributeTargets.Method)] | ||
// public class AutoQueryableAttribute : Attribute, IFilterFactory, IOrderedFilter | ||
// { | ||
// public string[] UnselectableProperties { get; set; } | ||
|
||
/// <inheritdoc /> | ||
public bool IsReusable { get; set; } | ||
// /// <inheritdoc /> | ||
// public bool IsReusable { get; set; } | ||
|
||
/// <inheritdoc /> | ||
public int Order { get; set; } | ||
// /// <inheritdoc /> | ||
// public int Order { get; set; } | ||
|
||
public IFilterMetadata CreateInstance(IServiceProvider serviceProvider) | ||
{ | ||
if (serviceProvider == null) | ||
{ | ||
throw new ArgumentNullException(nameof(serviceProvider)); | ||
} | ||
var profile = new AutoQueryableProfile | ||
{ | ||
UnselectableProperties = UnselectableProperties | ||
}; | ||
// public IFilterMetadata CreateInstance(IServiceProvider serviceProvider) | ||
// { | ||
// if (serviceProvider == null) | ||
// { | ||
// throw new ArgumentNullException(nameof(serviceProvider)); | ||
// } | ||
// var profile = new AutoQueryableProfile | ||
// { | ||
// UnselectableProperties = UnselectableProperties | ||
// }; | ||
|
||
return new AutoQueryableFilter(profile); | ||
} | ||
} | ||
} | ||
// return new AutoQueryableFilter(profile); | ||
// } | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
using System; | ||
using AutoQueryable.Helpers; | ||
using AutoQueryable.Models; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.Filters; | ||
//using System; | ||
//using AutoQueryable.Helpers; | ||
//using AutoQueryable.Models; | ||
//using Microsoft.AspNetCore.Mvc; | ||
//using Microsoft.AspNetCore.Mvc.Filters; | ||
|
||
namespace AutoQueryable.Filters | ||
{ | ||
public class AutoQueryableFilter : IActionFilter | ||
{ | ||
private readonly AutoQueryableProfile _autoQueryableProfile; | ||
//namespace AutoQueryable.Filters | ||
//{ | ||
// public class AutoQueryableFilter : IActionFilter | ||
// { | ||
// private readonly AutoQueryableProfile _autoQueryableProfile; | ||
|
||
public AutoQueryableFilter(AutoQueryableProfile autoQueryableProfile) | ||
{ | ||
_autoQueryableProfile = autoQueryableProfile; | ||
} | ||
public virtual void OnActionExecuting(ActionExecutingContext context) | ||
{ | ||
} | ||
// public AutoQueryableFilter(AutoQueryableProfile autoQueryableProfile) | ||
// { | ||
// _autoQueryableProfile = autoQueryableProfile; | ||
// } | ||
// public virtual void OnActionExecuting(ActionExecutingContext context) | ||
// { | ||
// } | ||
|
||
public virtual void OnActionExecuted(ActionExecutedContext context) | ||
{ | ||
dynamic query = ((ObjectResult)context.Result).Value; | ||
if (query == null) throw new Exception("Unable to retreive value of IQueryable from context result."); | ||
Type entityType = query.GetType().GenericTypeArguments[0]; | ||
// public virtual void OnActionExecuted(ActionExecutedContext context) | ||
// { | ||
// dynamic query = ((ObjectResult)context.Result).Value; | ||
// if (query == null) throw new Exception("Unable to retreive value of IQueryable from context result."); | ||
// Type entityType = query.GetType().GenericTypeArguments[0]; | ||
|
||
string queryString = context.HttpContext.Request.QueryString.HasValue ? context.HttpContext.Request.QueryString.Value : null; | ||
// Work on generic type directly, for dto projection | ||
context.Result = new OkObjectResult(QueryableHelper.GetAutoQuery(queryString, entityType, query, _autoQueryableProfile)); | ||
} | ||
} | ||
} | ||
// string queryString = context.HttpContext.Request.QueryString.HasValue ? context.HttpContext.Request.QueryString.Value : null; | ||
// // Work on generic type directly, for dto projection | ||
// context.Result = new OkObjectResult(QueryableHelper.GetAutoQuery(queryString, entityType, query, _autoQueryableProfile)); | ||
// } | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters