public ICollection <Product> Search(ProductSearchCriteriaDTO criteria) { var products = _db.Products.AsQueryable(); if (!string.IsNullOrEmpty(criteria.Name)) { products = products.Where(c => c.Name.ToLower().Contains(criteria.Name.ToLower())); } if (!string.IsNullOrEmpty(criteria.Code)) { products = products.Where(c => c.Code.ToLower().Contains(criteria.Code)); } if (criteria.FromSalesPrice > 0) { products = products.Where(c => c.Price >= criteria.FromSalesPrice); } if (criteria.ToSalesPrice > 0) { products = products.Where(c => c.Price <= criteria.ToSalesPrice); } return(products.ToList()); }
public ICollection <Product> Search(ProductSearchCriteriaDTO dto) { var products = _db.Products.Include(c => c.Shop).AsQueryable(); if (!string.IsNullOrEmpty(dto.Name)) { products = products.Where(c => c.Name.ToLower().Contains(dto.Name.ToLower())); } if (Equals(!string.IsNullOrEmpty(dto.Code))) { products = products.Where(c => c.Code.ToLower().Contains(c.Code.ToLower())); } if (dto.FromSalesPrice > 0) { products = products.Where(c => c.Price <= dto.ToSalesPrice); } if (dto.ShopId != null && dto.ShopId > 0) { products = products.Where(c => c.ShopId == dto.ShopId); } return(products.ToList()); }
static void Main(string[] args) { UnitofWork _unitofWork = new UnitofWork(); var searchCriteria = new ProductSearchCriteriaDTO() { Name = "Laptop", FromSalesPrice = 1000 }; var products = _unitofWork.ProductRepository.Search(searchCriteria); foreach (var product in products) { Console.WriteLine(GetProductInfo(product)); } }
public ICollection <Product> Search(ProductSearchCriteriaDTO dto) { return(_productRepository.Search(dto)); }