public async Task <SearchResult <Product> > Search(ProductSearchPattern searchPattern) { IQueryable <Product> query = _ctx.Products.AsQueryable(); int totalCount = query.Count(); // filters if (!String.IsNullOrWhiteSpace(searchPattern.SearchString)) { string searchString = searchPattern.SearchString.Trim(); query = query.Where(x => x.Name.Contains(searchString)); } // sorting query = query.OrderByDescending(x => x.Id); int filteredCount = query.Count(); // taking query = query.Skip(searchPattern.Skip()).Take(searchPattern.Take()); return(new SearchResult <Product> { Items = await query.ToListAsync(), TotalCount = totalCount, FilteredCount = filteredCount }); }
public async Task <IActionResult> Search(int pageNumber, int onPage, string searchString) { var abc = new ProductSearchPattern { PageNumber = pageNumber, OnPage = onPage, SearchString = searchString }; SearchResult <Product> searchResult = await productRepository.Search(abc); return(Ok(new SearchResult <ProductDto> { Items = searchResult.Items.Map(), TotalCount = searchResult.TotalCount, FilteredCount = searchResult.FilteredCount })); }