public PagerResult <T> Find(IEnumerable <Expression <Func <T, bool> > > filters, Pager pager, OrderBy orderBy)
        {
            var exec = this.Query.AsQueryable <T>();

            if (filters != null)
            {
                foreach (var f in filters)
                {
                    exec = exec.Where(f);
                }
            }

            var totalCount = pager != null && pager.IsValid() ? exec.Count() : 0;

            if (orderBy != null)
            {
                exec = orderBy.Apply(exec);
            }

            if (pager != null && pager.IsValid())
            {
                exec = exec.Skip((pager.PageNum - 1) * pager.PageSize).Take(pager.PageSize);
            }

            var result = new PagerResult <T>(exec.AsEnumerable <T>().ToArray());

            if (pager != null && pager.IsValid())
            {
                result.SetInfo(pager.PageNum, pager.PageSize, totalCount);
            }

            return(result);
        }
Exemple #2
0
        public async Task <PaginatedCollection <Stock> > GetAsync(IExpressionSpecification <Stock> specification, int offset, int limit, OrderBy <Stock> orderBy, CancellationToken cancellationToken)
        {
            IQueryable <Stock> stocks = _appDbContext.Set <Stock>()
                                        .Where(specification.Expression);

            stocks = orderBy.Apply(stocks);

            (int totalCount, List <Stock> stockList)
                = await stocks.PaginatedQueryAsync(offset, limit, cancellationToken);


            if (!stockList.Any())
            {
                throw new StockNotFoundException();
            }

            var paginatedCollection = new PaginatedCollection <Stock>(totalCount, stockList);

            return(paginatedCollection);
        }
        public async Task <PaginatedCollection <Order> > GetAsync(IExpressionSpecification <Order> specification, int offset, int limit, OrderBy <Order> orderBy, CancellationToken cancellationToken = default)
        {
            IQueryable <Order> books = _appDbContext.Set <Order>()
                                       .Include(order => order.OrderLines)
                                       .Where(specification.Expression);

            books = orderBy.Apply(books);

            (int totalCount, List <Order> orderList)
                = await books.PaginatedQueryAsync(offset, limit, cancellationToken);


            if (!orderList.Any())
            {
                throw new OrderNotFoundException();
            }

            var paginatedCollection = new PaginatedCollection <Order>(totalCount, orderList);

            return(paginatedCollection);
        }