public async Task <PagedList <ProductDto> > GetPagedListAsync(PageOptions options, string language, CancellationToken token) { var resultQuery = LoadRelatedData(); //searching if (!string.IsNullOrWhiteSpace(options.SearchBy)) { resultQuery = resultQuery.Where(Product.GetSearchQuery(options.SearchBy)); } //filtering if (options.GroupId != null) { resultQuery = resultQuery.Where(c => c.GroupId == options.GroupId); } if (options.SubstanceId != null) { resultQuery = resultQuery.Where(c => c.ActiveSubstanceId == options.SubstanceId); } //sorting if (!string.IsNullOrWhiteSpace(options.SortBy)) { resultQuery = resultQuery.ApplySort(options.SortBy); } var resultList = await resultQuery .Select(MultiLanguageSupport.ProductWithCurrentLanguage(language)) .ToListAsync(cancellationToken: token); return(PagedList <ProductDto> .ToPagedList(resultList, options.PageNumber, options.PageSize)); }
public async Task <ProductDto> GetByIdAsync(int productId, string language, CancellationToken token) { return(await LoadRelatedData() .Select(MultiLanguageSupport.SingleProductWithCurrentLanguage(language)) .FirstOrDefaultAsync(c => c.Id == productId, cancellationToken: token)); }