public ActionResult AddtoCart(int id)
        {
            Product product = new Product();
            product = db.Products.Find(id);

            if (product != null)
            {
                GetCart().AddItem(product, 1);
            }
            ViewData["newProduct"] = product;
            Session["newProduct"] = product;
            return RedirectToAction("CartDetail");
        }
Exemple #2
0
        public void AddItem(Product product, int quantity)
        {
            var currentCart = (from c in cartListCollection
                               where c.Product.ProductId == product.ProductId
                               select c).FirstOrDefault();

            if (currentCart != null)
            {
                currentCart.Quantity = currentCart.Quantity + quantity;
            }
            else
            {
                cartListCollection.Add(new CartList { Product = product, Quantity = quantity});
            }
        }
Exemple #3
0
 public void RemoveItem(Product product)
 {
     cartListCollection.RemoveAll(c => c.Product.ProductId == product.ProductId);
 }