public override void OnActionExecuting(ActionExecutingContext filterContext) { var repo = new CartRepository(Properties.Settings.Default.ConStr); if(filterContext.HttpContext.Session["cart"] != null) { var cartId = (int)filterContext.HttpContext.Session["cart"]; filterContext.Controller.ViewBag.CartCount = repo.GetCartCount(cartId); filterContext.Controller.ViewBag.CartId = cartId; } base.OnActionExecuting(filterContext); }
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 ActionResult Cart(int? cartId) { var cartRepo = new CartRepository(Properties.Settings.Default.ConStr); CartPageViewModel model = new CartPageViewModel(); if (cartId != null) { model.ItemsInCart = cartRepo.GetItemsInCart(cartId).Select(i => new CartPagePropertis { Item = i, TotalPerItem = (decimal)i.Quantity * i.Product.Price, }); } return View(model); }
public ActionResult UpdateQuantity(int quantity, int itemId) { var cartRepo = new CartRepository(Properties.Settings.Default.ConStr); cartRepo.UpdateQuantity(quantity, itemId); return Redirect("cart?cartid=" + Session["cart"]); }
public void DeleteItem(int itemId) { var cartRepo = new CartRepository(Properties.Settings.Default.ConStr); cartRepo.DeleteItem(itemId); }