Ejemplo n.º 1
0
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            if (context.Exception != null)
            {
                return;
            }

            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];

            var commands = context.HttpContext.Request.Query.ContainsKey("commands") ? context.HttpContext.Request.Query["commands"] : new StringValues();

            var data = QueryableHelper.GetAutoQuery(commands, entityType, query,
                                                    new AutoQueryableProfile {
                UnselectableProperties = new string[0]
            });

            var toArray = typeof(Enumerable).GetMethod("ToArray").MakeGenericMethod(typeof(object));

            var fetchedData = toArray.Invoke(null, new object[] { data });

            var total = System.Linq.Queryable.Count(query);

            context.Result = new OkObjectResult(new DataResult {
                Data = fetchedData, Total = total
            });
        }
Ejemplo n.º 2
0
        public override void OnActionExecuted(HttpActionExecutedContext context)
        {
            var content = context.Response.Content as ObjectContent;

            if (content != null)
            {
                dynamic query = content.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.Request.RequestUri.Query;
                var    result      = QueryableHelper.GetAutoQuery(queryString, entityType, query, new AutoQueryableProfile {
                    SelectableProperties      = SelectableProperties,
                    UnselectableProperties    = UnselectableProperties,
                    SortableProperties        = SortableProperties,
                    UnSortableProperties      = UnSortableProperties,
                    GroupableProperties       = GroupableProperties,
                    UnGroupableProperties     = UnGroupableProperties,
                    AllowedClauses            = AllowedClauses,
                    DisAllowedClauses         = DisAllowedClauses,
                    AllowedConditions         = AllowedConditions,
                    DisAllowedConditions      = DisAllowedConditions,
                    AllowedWrapperPartType    = AllowedWrapperPartType,
                    DisAllowedWrapperPartType = DisAllowedWrapperPartType,
                    MaxToTake = MaxToTake,
                    MaxToSkip = MaxToSkip,
                    MaxDepth  = MaxDepth
                });
                context.Response.Content = new ObjectContent(result.GetType(), result, new JsonMediaTypeFormatter());
            }
        }
Ejemplo n.º 3
0
        public static dynamic AutoQueryable <TEntity>(this IQueryable <TEntity> query, string queryString, AutoQueryableProfile profile = null) where TEntity : class
        {
            profile = profile ?? new AutoQueryableProfile();
            Type entityType = typeof(TEntity);

            return(QueryableHelper.GetAutoQuery(queryString, entityType, query, profile));
        }
Ejemplo n.º 4
0
        public override 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;

            context.Result = new OkObjectResult(QueryableHelper.GetAutoQuery(queryString, entityType, query, new AutoQueryableProfile
            {
                SelectableProperties      = SelectableProperties,
                UnselectableProperties    = UnselectableProperties,
                SortableProperties        = SortableProperties,
                UnSortableProperties      = UnSortableProperties,
                GroupableProperties       = GroupableProperties,
                UnGroupableProperties     = UnGroupableProperties,
                AllowedClauses            = AllowedClauses,
                DisAllowedClauses         = DisAllowedClauses,
                AllowedConditions         = AllowedConditions,
                DisAllowedConditions      = DisAllowedConditions,
                AllowedWrapperPartType    = AllowedWrapperPartType,
                DisAllowedWrapperPartType = DisAllowedWrapperPartType,
                MaxToTake    = MaxToTake,
                MaxToSkip    = MaxToSkip,
                MaxDepth     = MaxDepth,
                ProviderType = ProviderType,
                UseBaseType  = UseBaseType
            }));
        }
        public override 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;

            context.Result = new OkObjectResult(QueryableHelper.GetAutoQuery(queryString, entityType, query, new AutoQueryableProfile {
                UnselectableProperties = UnselectableProperties
            }));
        }
Ejemplo n.º 6
0
        public override void OnActionExecuted(HttpActionExecutedContext context)
        {
            var content = context.Response.Content as ObjectContent;

            if (content != null)
            {
                dynamic query = content.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.Request.RequestUri.Query;
                var    result      = QueryableHelper.GetAutoQuery(queryString, entityType, query, new AutoQueryableProfile {
                    UnselectableProperties = UnselectableProperties
                });
                context.Response.Content = new ObjectContent(result.GetType(), result, new JsonMediaTypeFormatter());
            }
        }
        public static void AutoQueryable(this AfterPipeline afterPipeline, NancyContext context, dynamic query, AutoQueryableProfile profile = null)
        {
            context.Items.Add("autoqueryable-query", query);

            afterPipeline += ctx =>
            {
                if (query == null)
                {
                    throw new Exception("Unable to retreive value of IQueryable from context result.");
                }
                Type entityType = query.GetType().GenericTypeArguments[0];

                string queryString = ctx.Request.Url.Query;

                ctx.Response.Contents = stream =>
                {
                    using (var writer = new StreamWriter(stream))
                    {
                        var result = QueryableHelper.GetAutoQuery(queryString, entityType, query, profile);
                        writer.Write(JsonConvert.SerializeObject(result));
                    }
                };
            };
        }