コード例 #1
0
        public ActionResult RemoveFromCart(int id)
        {
            var cart = ShoppingCartLogic.GetCart(this.HttpContext);

            var     shoppingCart    = new ShoppingCartLogic();
            int     productId       = shoppingCart.GetCartItemProductId(id);
            var     productService  = new ProductLogic();
            Product productToRemove = productService.FindProduct(productId);

            int itemCount = cart.RemoveFromCart(id);

            var removeViewModel = new ShoppingCartRemoveVM
            {
                Message = Server.HtmlEncode(productToRemove.Name) +
                          " has been removed from your shopping cart.",
                CartCount    = cart.GetCount(),
                CartSubTotal = cart.GetSubtotal(),
                CartSalesTax = cart.GetSalesTax(),
                CartTotal    = cart.GetTotal(),
                ItemCount    = itemCount,
                DeleteId     = id,
            };

            return(Json(removeViewModel));
        }
コード例 #2
0
        public ActionResult AddToCart(int id)
        {
            var productService = new ProductLogic();
            var productAdded   = productService.FindProduct(id);

            ShoppingCartLogic cart = ShoppingCartLogic.GetCart(this.HttpContext);

            cart.AddToCart(productAdded);

            return(RedirectToAction("Index"));
        }
コード例 #3
0
        // GET: Products/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var     productService = new ProductLogic();
            Product product        = productService.FindProduct(id);

            if (product == null)
            {
                return(HttpNotFound());
            }
            return(View(product));
        }
コード例 #4
0
        // GET: StoreManager/Product/Edit/5
        public ActionResult ProductEdit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var     productService = new ProductLogic();
            Product product        = productService.FindProduct(id);

            if (product == null)
            {
                return(HttpNotFound());
            }
            var categoryList = new CategoryLogic();

            ViewBag.CategoryId = categoryList.SetCategoryViewBag(id);
            return(View(product));
        }