Beispiel #1
0
        public void Add(CartItem item)
        {
            CartItem existedItem = Items.Where(i => i.ProID == item.ProID).FirstOrDefault();

            if (existedItem != null)
            {
                existedItem.Quantity += item.Quantity;
            }
            else
            {
                Items.Add(item);
            }
        }
Beispiel #2
0
        public ActionResult AddToCart(CartItem item)
        {
            int cartItemQuantity = CurrentContext.GetCart().getQuantityPro(item.ProID);
            using (QLBHEntities ctx = new QLBHEntities())
            {
                var pro = ctx.Products.Where(p => p.ProID == item.ProID).First();

                if (pro.Quantity >= (item.Quantity + cartItemQuantity))
                {
                    CurrentContext.GetCart().Add(item);
                    return RedirectToAction("Detail", "Product", new { id = item.ProID });
                }
                else
                {
                    Session["Error"] = "Loi";
                    return RedirectToAction("Detail", "Product", new { id = item.ProID });
                }
            }
        }
Beispiel #3
0
        public ActionResult Add1ToCart(int id)
        {
            CartItem item = new CartItem();
            item.ProID = id;
            item.Quantity = 1;
            int cartItemQuantity = CurrentContext.GetCart().getQuantityPro(item.ProID);
            using (QLBHEntities ctx = new QLBHEntities())
            {
                var pro = ctx.Products.Where(p => p.ProID == item.ProID).First();

                if (pro.Quantity >= (item.Quantity + cartItemQuantity))
                {
                    CurrentContext.GetCart().Add(item);
                }
                else
                {
                    Session["Error"] = "Loi";
                }
            }
            int numberItem = CurrentContext.GetCart().GetNumberOfItem();
            return Json(numberItem);
        }