예제 #1
0
        public static IQueryable <TModel> ApplyOrder <TModel>(this IQueryable <TModel> query, DataOptions options, DataOptionsQueryCreator <TModel> creator = null)
        {
            if (options != null && options.Order != null && options.Order.By != null && options.Order.By.Count > 0)
            {
                if (creator == null)
                {
                    creator = new DataOptionsQueryCreator <TModel>(options);
                }

                query = query.OrderBy(creator.GetOrderQuery());
            }

            return(query);
        }
예제 #2
0
        public static IQueryable <TModel> ApplyFilter <TModel>(this IQueryable <TModel> query, DataOptions options, DataOptionsQueryCreator <TModel> creator = null)
        {
            if (options != null &&
                options.Filter != null &&
                ((options.Filter.Where != null && options.Filter.Where.Count > 0) ||
                 (options.Filter.Inner != null && options.Filter.Inner.Count > 0)))
            {
                if (creator == null)
                {
                    creator = new DataOptionsQueryCreator <TModel>(options);
                }

                query = query.Where(creator.GetFilterQuery(), creator.GetFilterParameters());
            }

            return(query);
        }
예제 #3
0
        public static DataListResponse <TModel> ToDataListResponse <TModel>(this IQueryable <TModel> query, DataOptions options)
        {
            var creator = new DataOptionsQueryCreator <TModel>(options);

            query = query.ApplyFilter(options, creator);

            if (options.HasPaging())
            {
                var totalCount = query.ToRowCountFutureValue();

                query = query.ApplyOrder(options, creator);
                query = query.ApplyPaging(options);
                var items = query.ToFuture();

                return(new DataListResponse <TModel>(items.ToList(), totalCount.Value));
            }
            else
            {
                query = query.ApplyOrder(options, creator);
                var items = query.ToList();

                return(new DataListResponse <TModel>(items, items.Count));
            }
        }