Beispiel #1
0
        public ActionResult GetCart()
        {
            var cart  = new Service.ShoppingCart();
            var carts = cart.GetCart(this.HttpContext);

            // var carts = Service.ShoppingCart.GetCart();
            if (carts.CartItems.Count == 0)
            {
                carts.CartItems.Add(
                    new CartItem()
                {
                    Id       = 1,
                    CartId   = 1,
                    Quantity = 0,
                }

                    );
            }
            else
            {
                carts.CartItems.First().Quantity += 1;
            }


            return(Content(string.Format("目前產品數量{0}個", carts.CartItems.Count)));
        }
        public PartialViewResult CartSummary()
        {
            var cart        = new Service.ShoppingCart();
            var cartSummary = cart.GetCartSummary(this.HttpContext);

            return(PartialView(cartSummary));
        }
        // GET: ShoppingCart

        public ActionResult Index()
        {
            var cart  = new Service.ShoppingCart();
            var model = cart.GetCartItems(this.HttpContext);

            return(View(model));
        }
        public ActionResult RemoveFromCart(int Id)
        {
            var cart = new Service.ShoppingCart();

            cart.RemoveFromCart(this.HttpContext, Id);

            return(RedirectToAction("Index"));
        }
        //public ActionResult AddToCart(CartItem cartItem)
        //{
        //    var item = context.CartItems.FirstOrDefault(i => i.CartId == cartItem.Id);
        //    //將產品加入
        //    if (cartItem== null)
        //    {
        //        cartItem = new CartItem()
        //        {
        //            CartId = item.Id,
        //            ProductId = productId,
        //            Quantity = 1
        //        };
        //        else{

        //        }
        //    }
        //    return RedirectToAction("Index");
        //}


        public ActionResult AddToCart(int id, int quantity)
        {
            var cart = new Service.ShoppingCart();

            cart.AddtoCart(this.HttpContext, id, quantity);//Change

            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult Checkout(Order order)
        {
            var cart      = new Service.ShoppingCart();
            var cartItems = cart.GetCartItems(this.HttpContext);

            order.Email = User.Identity.Name;

            var o = new Orders();

            o.CreateOrder(order, cartItems);

            cart.EmptyCart(this.HttpContext);

            return(RedirectToAction("ThankYou", new { OrderId = order.Id }));
        }