Example #1
0
        public IActionResult Get([FromQuery] ProductSearchCriteriaVm productSearchCriteria)
        {
            var products = _productManager.GetByCriteria(productSearchCriteria);

            if (products.Any())
            {
                return(Ok(products));
            }

            return(NoContent());
        }
Example #2
0
        public ICollection <Product> GetByCriteria(ProductSearchCriteriaVm productSearchCriteria)
        {
            var products = _db.Products.AsQueryable();

            if (productSearchCriteria != null)
            {
                if (!string.IsNullOrEmpty(productSearchCriteria.Name))
                {
                    products = products.Where(p => p.Name.ToLower().Contains(productSearchCriteria.Name.ToLower()));
                }

                if (productSearchCriteria.FromPrice > 0)
                {
                    products = products.Where(p => p.Price >= productSearchCriteria.FromPrice);
                }

                if (productSearchCriteria.ToPrice > 0)
                {
                    products = products.Where(p => p.Price <= productSearchCriteria.ToPrice);
                }
            }

            return(products.ToList());
        }
Example #3
0
 public ICollection <Product> GetByCriteria(ProductSearchCriteriaVm productSearchCriteria)
 {
     return(_productRepository.GetByCriteria(productSearchCriteria));
 }