コード例 #1
0
        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
            });
        }
コード例 #2
0
        public IActionResult GetProducts([FromQuery] ProductsQueryModel query)
        {
            var result = _service.GetProducts(query);

            return(Ok(result));
        }