Пример #1
0
        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);
        }
Пример #2
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);
 }
Пример #3
0
 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);
 }
Пример #4
0
 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"]);
 }
Пример #5
0
 public void DeleteItem(int itemId)
 {
     var cartRepo = new CartRepository(Properties.Settings.Default.ConStr);
     cartRepo.DeleteItem(itemId);
 }