public PartialViewResult FilterProducts(ProductFilterModel model) { List<Product> p = new WCFProduct().GetProducts().ToList(); List<ProductModel> products = new List<ProductModel>(); foreach (Product pr in p) { ProductModel pm = new ProductModel(); pm.ID = pr.ID; pm.Features = pr.Features; pm.DateListed = pr.Date_Listed; pm.Name = pr.Name; pm.Image = pr.Image; pm.Price = (double)pr.Price; pm.StockAmount = pr.Stock_Amount; pm.AverageRate = new WCFProductClient().GetProductAverageRating(pr.ID); if (model.CategoryName != null) { if (pr.Category != null && pr.Category.Contains(model.CategoryName)) { products.Add(pm); } } else if (model.ProductName != null) { if (pm.Name.Contains(model.ProductName)) { products.Add(pm); } } else if (model.smallestPrice != 0 && model.greatestPrice != 0 && model.smallestPrice != null && model.greatestPrice != null) { if (pm.Price >= model.smallestPrice && pm.Price <= model.greatestPrice) { products.Add(pm); } } else { products.Add(pm); } if (model.sortByPrice == true) { if (model.sortDescending == true) { products = products.OrderByDescending(temP => temP.Price).ToList(); } else { products = products.OrderBy(temP => temP.Price).ToList(); } } } return PartialView("_Filters", products); }
public ActionResult Home() { try { List<Product> p = new WCFProduct().GetProducts().ToList(); List<ProductModel> products = new List<ProductModel>(); foreach (Product pr in p) { ProductModel pm = new ProductModel(); pm.ID = pr.ID; pm.Features = pr.Features; pm.DateListed = pr.Date_Listed; pm.Name = pr.Name; pm.Image = pr.Image; pm.Price = (double)pr.Price; pm.StockAmount = pr.Stock_Amount; pm.AverageRate = new WCFProductClient().GetProductAverageRating(pr.ID); products.Add(pm); } return View("Home", products); } catch { return View(); } }