示例#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);
 }