Esempio n. 1
0
 /// <summary>
 /// 将商品添加到购物车中
 /// </summary>
 private void AddBookToCart()
 {
     int bookId;
     if (int.TryParse(Request.QueryString["id"], out bookId))
     {
         BooksBLL bb = new BooksBLL();
         Books book = bb.GetModel(bookId);
         if (book != null)
         {
             CartBLL cb = new CartBLL();
             Model.Cart cart = cb.GetModel(LoginUser.Id, bookId);
             if (cart != null)
             {
                 cart.Count = cart.Count + 1;
                 cb.Update(cart);
             }
             else
             {
                 Model.Cart newCart = new Model.Cart();
                 newCart.Book.Id = bookId;
                 newCart.Count = 1;
                 newCart.UserId = LoginUser.Id;
                 cb.Add(newCart);
             }
         }
         else
         {
             Response.Redirect("/ShowMsg.aspx?m=" + HttpUtility.UrlEncode("此商品不存在!"));
         }
     }
 }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string res = "no";
            string oper = context.Request["oper"];
            if (oper == "change")
            {
                int id;
                if (int.TryParse(context.Request["id"], out id))
                {
                    CartBLL bll = new CartBLL();
                    Cart model = bll.GetModel(id);
                    if (model != null)
                    {
                        model.Count = Convert.ToInt32(context.Request["count"]);
                        bll.Update(model);
                        res = "yes";
                    }
                }

            }
            else if (oper == "del")
            {
                int id;
                if (int.TryParse(context.Request["id"], out id))
                {
                    CartBLL bll = new CartBLL();
                    if (bll.Delete(id))
                    {
                        res = "yes";
                    }
                }
            }
            context.Response.Write(res);
        }