public PagedResultDto <ProductOutput> GetAllProducts(GetAllProductInput input) { if (input.MaxResultCount <= 0) { input.MaxResultCount = AppConsts.MaxResultCount; } if (String.IsNullOrEmpty(input.Sorting)) { input.Sorting = AppConsts.DefaultSortingField; } var products = _productRepository.GetAllIncluding(x => x.Variants) .WhereIf(input.TenantId.HasValue, t => t.TenantId == input.TenantId.Value) .WhereIf(input.CategoryId.HasValue, t => t.CategoryId == input.CategoryId.Value) .WhereIf(input.BrandId.HasValue, t => t.BrandId == input.BrandId.Value) .WhereIf(!String.IsNullOrEmpty(input.Name), t => t.Name.Contains(input.Name)) .WhereIf(!String.IsNullOrEmpty(input.Code), t => t.Code.Contains(input.Code)) .OrderBy(input.Sorting) .PageBy(input) .ToList() ; var productsCount = products.Count(); return(new PagedResultDto <ProductOutput> { TotalCount = productsCount, Items = products.MapTo <List <ProductOutput> >() }); }
public async Task <JsonResult> GetProducts(GetAllProductInput input) { var result = await _productService.GetAll(input); return(Json(new { Count = result.TotalCount, Data = result.Items })); }