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 BuyProducts() { Order order = new Order(); order.ID = Guid.NewGuid(); order.Username = @User.Identity.Name; order.DateOrdered = DateTime.Now; //products to add to the order List<Cart_Product> cartProductsToBuy = new List<Cart_Product>(); foreach (Cart_Product cp in new WCFCart_OrderClient().GetCart(@User.Identity.Name)) { Product p = new WCFProduct().GetProductByID(cp.ProductID); if (p.Stock_Amount - cp.Quantity >= 0) { cartProductsToBuy.Add(cp); //delete cart product new WCFCart_Order().DeleteProductFromCart(cp); //decrease stock p.Stock_Amount = p.Stock_Amount - cp.Quantity; new WCFProduct().UpdateProduct(p); } } //add the order new WCFCart_OrderClient().AddOrder(order, cartProductsToBuy.ToArray()); //testing return RedirectToAction("Home", "Product"); }
public ActionResult Home() { try { List<Product> p = new WCFProduct().GetProducts().ToList(); return View("Home", p); } catch { return View(); } }
/// <summary> /// This methods return the top rated product /// </summary> /// <returns></returns> public Product GetHighestRatingProduct() { List<Product> products = new ProductRep().GetProducts().ToList(); Product highestRated = products[0]; WCFProduct wcfP = new WCFProduct(); foreach (Product p in products) { if (wcfP.GetProductAverageRating(p.ID) > wcfP.GetProductAverageRating(highestRated.ID)) { highestRated = p; } } return highestRated; }
public ActionResult BuyProduct(Guid productID) { Order order = new Order(); order.ID = Guid.NewGuid(); order.Username = @User.Identity.Name; order.DateOrdered = DateTime.Now; bool purchaseSuccess = true; //products to add to the order List<Cart_Product> cartProductsToBuy = new List<Cart_Product>(); Cart_Product cp = new WCFCart_OrderClient().GetCartProduct(order.Username, productID); Product p = new WCFProduct().GetProductByID(cp.ProductID); if (p.Stock_Amount - cp.Quantity >= 0) { cartProductsToBuy.Add(cp); //delete cart product new WCFCart_Order().DeleteProductFromCart(cp); //decrease stock p.Stock_Amount = p.Stock_Amount - cp.Quantity; new WCFProduct().UpdateProduct(p); } else { purchaseSuccess = false; } if (purchaseSuccess) { Session["CartProductNameError"] = ""; //add the order new WCFCart_OrderClient().AddOrder(order, cartProductsToBuy.ToArray()); } else { Session["CartProductNameError"] = "Your amount for the Product" + p.Name + "appears to be more than we have in stock. Sorry for the inconveniece."; } return RedirectToAction("Cart"); }
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(); } }
public ActionResult ShowProduct(Guid id) { try{ Product p = new WCFProduct().GetProductByID(id); return View("Product", p); }catch{ return View(); } }