public IActionResult Get([FromQuery] ProductSearchCriteriaVm productSearchCriteria) { var products = _productManager.GetByCriteria(productSearchCriteria); if (products.Any()) { return(Ok(products)); } return(NoContent()); }
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()); }
public ICollection <Product> GetByCriteria(ProductSearchCriteriaVm productSearchCriteria) { return(_productRepository.GetByCriteria(productSearchCriteria)); }