示例#1
0
        public ActionResult AddToCart(string id, int Quantity)
        {
            Cart   cart;
            string cookiesValue;

            if (context.Request.Cookies.Keys.Count == 0)
            {
                cookiesValue = Response.Cookies["id"].Value = GetRandomString();
                //     HttpCookie = new HttpCookie();
                //   HttpCookie.Expires = DateTime.Now.AddHours(1);
            }

            cookiesValue = context.Request.Cookies.Get("id").Value;
            cart         = new Cart
            {
                ProductId    = id,
                Quantity     = Quantity,
                CookiesValue = cookiesValue
            };
            CartService.AddNewCart(cart);
            return(RedirectToAction("Index")); // ajax or page update
        }