예제 #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);
     }
 }