Ejemplo n.º 1
0
        public static ResultViewModel <T> GetData <T>(IQueryable <T> results, string sorting, string filter, int skip, int take, int pageSize, int page)
        {
            filter = filter == "null" ? string.Empty : filter;
            if (!string.IsNullOrEmpty(filter) && filter != "null")
            {
                results = GridService.ApplyfilterToProducts(results, filter);
            }

            if (!string.IsNullOrEmpty(sorting) && sorting != "null")
            {
                results = GridService.SortListProducts(results, sorting);
            }

            var data = results
                       .Skip(skip)
                       .Take(pageSize);

            var result = new ResultViewModel <T>()
            {
                Data  = data,
                Count = string.IsNullOrWhiteSpace(filter)
                        ? results.Count()
                        : data.Count()
            };

            return(result);
        }
Ejemplo n.º 2
0
        public static IQueryable <T> SortListProducts <T>(IQueryable <T> results, string sorting)
        {
            var sortList = JsonConvert.DeserializeObject <List <SortDescription> >(sorting);

            if (sortList.Any())
            {
                var orderByExpression = GridService.GetOrderByExpression <T>(sortList[0].field);
                results = GridService.OrderByDir <T>(results, sortList[0].dir, orderByExpression);
            }
            return(results);
        }