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); }
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(); } }
private void detach_CartItems(CartItem entity) { this.SendPropertyChanging(); entity.Product = null; }
private void attach_CartItems(CartItem entity) { this.SendPropertyChanging(); entity.Product = this; }
partial void DeleteCartItem(CartItem instance);
partial void UpdateCartItem(CartItem instance);
partial void InsertCartItem(CartItem instance);
private bool CheckIfItemIsAlreadyInCart(CartItem items) { using (var context = new ECommerceDbDataContext(_conStr)) { return context.CartItems.Any(c => c.CartId == items.CartId && c.ProductId == items.ProductId); } }