public async Task <IEnumerable <Product> > Get([FromQuery] string searchTerm) { IEnumerable <Product> result = null; if (String.IsNullOrEmpty(searchTerm)) { result = await repository.All(); } else { result = await repository.Search(searchTerm); } return(result); }
public SearchResults <ProductModel> GetProducts(ProductsQueryModel query) { var products = query.CategoryId == 0 ? _repo.All().ToList() : GetProductsForCategory(query.CategoryId).ToList(); query.Predicate = query.Term == null ? query.Predicate : x => x.ProductTitle.ToLower().Contains(query.Term.ToLower()) || x.ProductDescription.ToLower().Contains(query.Term.ToLower()) || x.SKU.ToLower().Contains(query.Term.ToLower()); var results = _repo.Query(products, query).ToList(); var total = _repo.Count(); return(new SearchResults <ProductModel>() { Results = results, Total = total }); }