public ActionResult Cart(ProdutViewModel model, FormCollection form) { var productId = Convert.ToInt16(form["productId"]); var quantity = Convert.ToInt16(form["Quantity"]); ShoppingCart cart = new ShoppingCart(); //Order order = new Order(); try { ProductInfo objProductDetails = new ProductInfo(); ////Customer customer = new Customer(); using (ECommerce objEntity = new ECommerce()) { objProductDetails = objEntity.ProductInfoes.Where(p => p.ProductID == productId).FirstOrDefault(); if (objProductDetails != null) { cart.ProductName = objProductDetails.ProductName; cart.Quantity = quantity; decimal v = (quantity * objProductDetails.ProductPrice); cart.TotalAmount = v; objEntity.ShoppingCarts.Add(cart); objEntity.SaveChanges(); //Store cart products in cookie// //HttpCookie cookies = new HttpCookie("Product"); //cookies["Product"] = JsonConvert.SerializeObject(cart); } } } catch (Exception ex) { Console.WriteLine("Product cannot be added in cart at this time:", ex); } return(View()); //return View("~/Views/ShoppingCart/Cart.cshtml"); }
// GET: OrderHistory public ActionResult Index() { ProdutViewModel product = new ProdutViewModel(); var customerid = Convert.ToInt32(Session["CustomerID"]); var result = CartHistoryDetails(customerid); return(View(result)); }
// GET: OrderHistory public ActionResult Index() { ProdutViewModel product = new ProdutViewModel(); using (ECommerce context = new ECommerce()) { product.ShoppingCart = context.ShoppingCarts.ToList(); } return(View(product)); }
// private ShoppingCart cart = new ShoppingCart(); // GET: ProductInfoes public ActionResult Details() { ProdutViewModel product = new ProdutViewModel(); product.ProductCategory = db.ProductCategories.ToList(); product.ProductInfo = db.ProductInfoes.ToList(); //var productInfoes = db.ProductInfoes.Include(p => p.ProductCategory).ToList(); return(View(product)); /*return View(from pro in db.ProductInfoes.Take(1) * select pro);*/ }
public ActionResult AddToCart(int productId) { ProdutViewModel objProductDetails = new ProdutViewModel(); if (objProductDetails != null) { using (ECommerce objEntity = new ECommerce()) { objProductDetails.ProductDetails = objEntity.ProductInfoes.Where(p => p.ProductID == productId).Include(p => p.ProductCategory).FirstOrDefault(); } return(View(objProductDetails)); } else { return(View("Details", "ProductInfoes")); } }