Пример #1
0
 public ActionResult AddToCart(CartItem items, int quantity)
 {
     var cartRepo = new CartRepository(Properties.Settings.Default.ConStr);
     if (Session["cart"] == null)
     {
         Cart cart = cartRepo.CreateCart();
         Session["cart"] = cart.CartId;
     }
     items.CartId = (int)Session["cart"];
     items.Quantity = quantity;
     cartRepo.AddToCart(items);
     return Json(new { CartCount = cartRepo.GetCartCount((int)Session["cart"]), CartId = (int)Session["cart"] }, JsonRequestBehavior.AllowGet);
 }
Пример #2
0
        public void AddToCart(CartItem items)
        {
            using (var context = new ECommerceDbDataContext(_conStr))
            {
                if(CheckIfItemIsAlreadyInCart(items))
                {
                    var updateItem = context.CartItems.Where(i => i.CartId == items.CartId && i.ProductId == items.ProductId).FirstOrDefault();
                    updateItem.Quantity += items.Quantity;
                }
                else
                {
                    context.CartItems.InsertOnSubmit(items);
                }

                context.SubmitChanges();
            }
        }
Пример #3
0
		private void detach_CartItems(CartItem entity)
		{
			this.SendPropertyChanging();
			entity.Product = null;
		}
Пример #4
0
		private void attach_CartItems(CartItem entity)
		{
			this.SendPropertyChanging();
			entity.Product = this;
		}
Пример #5
0
 partial void DeleteCartItem(CartItem instance);
Пример #6
0
 partial void UpdateCartItem(CartItem instance);
Пример #7
0
 partial void InsertCartItem(CartItem instance);
Пример #8
0
 private bool CheckIfItemIsAlreadyInCart(CartItem items)
 {
     using (var context = new ECommerceDbDataContext(_conStr))
     {
         return context.CartItems.Any(c => c.CartId == items.CartId && c.ProductId == items.ProductId);
     }
 }