public async Task <PaginatedList <PageShoplistIngredientCommandResult> > GetPageAsync(PageShoplistIngredientCommand command)
        {
            var source = _context.ShoplistIngredient.AsNoTracking().AsExpandable();
            var outer  = PredicateBuilder.New <ShoplistIngredientInfo>(true);

            if (command.ShoplistId.Any())
            {
                outer = outer.Start(x => command.ShoplistId.Contains(x.ShoplistId.Value));
            }

            if (command.IngredientId.Any())
            {
                outer = outer.Start(x => command.IngredientId.Contains(x.IngredientId.Value));
            }

            if (command.AmountTypeId.Any())
            {
                outer = outer.Start(x => command.AmountTypeId.Contains(x.AmountTypeId.Value));
            }

            if (!string.IsNullOrEmpty(command.TextToSearch))
            {
                var inner = PredicateBuilder.New <ShoplistIngredientInfo>();
                inner = inner.Start(ShoplistIngredientSpecs.TextToSearch(command.TextToSearch));
                outer = outer.And(inner);
            }

            var count = await source.Where(outer).CountAsync();

            var items = await source.Where(outer)
                        .Skip(command.SkipNumber)
                        .Take(command.PageSize)
                        .Include(x => x.Shoplist)
                        .Include(x => x.Ingredient)
                        .Include(x => x.AmountType)
                        .Select(ShoplistIngredientSpecs.AsPageShoplistIngredientCommandResult)
                        .ToListAsync();

            return(new PaginatedList <PageShoplistIngredientCommandResult>(items, count, command.PageNumber, command.PageSize));
        }
Esempio n. 2
0
 public virtual async Task <PaginatedList <PageShoplistIngredientCommandResult> > GetPageAsync(PageShoplistIngredientCommand command)
 {
     return(await _repository.GetPageAsync(command));
 }