Ejemplo n.º 1
0
        public ExtJsReader <TContext, TEntity> CanFilterBy(Expression <Func <TEntity, object> > expression)
        {
            string key = Lambda.ExtractMemberName(expression);

            return(CanFilterBy(key, expression));
        }
Ejemplo n.º 2
0
        public ExtJsReader <TContext, TEntity> CanFilterByCustom(Expression <Func <TEntity, object> > leftExpression, Expression <Func <TEntity, object> > rightExpression)
        {
            string key = Lambda.ExtractMemberName(leftExpression);

            return(CanFilterBy(key, rightExpression));
        }
Ejemplo n.º 3
0
        public override ExtJsResult ExecuteQuery()
        {
            var query = _query;

            var filterFn = _page.Server.UrlDecode(_page.Request.Unvalidated["filter"]);

            if (!filterFn.IsEmpty())
            {
                var filtersArray = Json.Decode(filterFn);
                foreach (var filter in filtersArray)
                {
                    string key = filter.property ?? filter.field;
                    if (string.IsNullOrEmpty(key) || !_filters.ContainsKey(key))
                    {
                        continue;
                    }

                    var tempExpr = _filters[key];
                    var resExpr  = Lambda.ModifyExpression(tempExpr, (object)filter.value);

                    query = query.Where(resExpr);
                }
            }

            var isOrdered = false;

            var sortFn = _page.Server.UrlDecode(_page.Request.Unvalidated["sort"]);

            if (!sortFn.IsEmpty())
            {
                var sortersArray = Json.Decode(sortFn);
                foreach (var sort in sortersArray)
                {
                    string key = sort.property;
                    if (!string.IsNullOrEmpty(key) && _sorters.ContainsKey(key))
                    {
                        var expr = _sorters[key];
                        if (isOrdered)
                        {
                            var ordered = query as IOrderedQueryable <TEntity>;
                            query = ordered.ThenBy(expr);
                        }
                        else
                        {
                            query = query.OrderBy(expr);
                        }

                        isOrdered = true;
                    }
                }
            }

            if (isOrdered)
            {
                //var ordered = (IOrderedQueryable<TEntity>)query;
                //query = ordered.ThenBy(_setOrderBy(ordered));
            }
            else
            {
                query = _orderByExpression(query);
            }

            var total = query.Count();

            if (!_page.Request["limit"].IsEmpty())
            {
                var start = _page.Request["start"].AsInt(0);
                if (start > total)
                {
                    start = 0;
                }

                var limit = _page.Request["limit"].AsInt(25);

                query = query.Skip(start).Take(limit);
            }

            var result = new ExtJsResult(_page.Response)
            {
                msg     = "",
                success = true,
                total   = total,
                data    = query.ToList()
            };

            return(result);
        }