コード例 #1
0
ファイル: EidtCart.ashx.cs プロジェクト: supeng4587/book_shop
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int cartId = Convert.ToInt32(context.Request["cartId"]);
            int count  = Convert.ToInt32(context.Request["Count"]);

            BLL.CartBLL     cartManager = new BLL.CartBLL();
            Model.CartModel cartModel   = cartManager.GetModel(cartId);
            if (cartModel != null)
            {
                cartModel.Count = count;
                if (cartManager.Update(cartModel))
                {
                    context.Response.Write("ok");
                }
                else
                {
                    context.Response.Write("no");
                }
            }
            else
            {
                context.Response.Write("no");
            }
        }
コード例 #2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            BLL.UsersBLL userManager = new BLL.UsersBLL();
            if (userManager.ValidateUserLogin())
            {
                int bookId = Convert.ToInt32(context.Request["bookId"]);

                //
                BLL.BooksBLL     bookManger = new BLL.BooksBLL();
                Model.BooksModel bookModel  = bookManger.GetModel(bookId);
                if (bookModel != null)
                {
                    int             userId      = ((Model.UsersModel)context.Session["userInfo"]).Id;
                    BLL.CartBLL     cartManager = new BLL.CartBLL();
                    Model.CartModel cartModel   = cartManager.GetModel(userId, bookId);
                    if (cartModel != null)
                    {
                        cartModel.Count += 1;
                        cartManager.Update(cartModel);
                    }
                    else
                    {
                        cartModel        = new Model.CartModel();
                        cartModel.Count  = 1;
                        cartModel.UserId = userId;
                        cartModel.BookId = bookId;
                        cartManager.Add(cartModel);
                    }
                    context.Response.Write("{\"action\":\"have\",\"message\":\"已添加到购物车\"}");
                }
                else
                {
                    context.Response.Write("{\"action\":\"notHave\",\"message\":\"无此商品\"}");
                }

                //context.Response.Write("{\"action\":\"ok\",\"message\":\"登录成功\"}");
            }
            else
            {
                context.Response.Write("{\"action\":\"notLogin\",\"message\":\"您还没有登陆\"}");
            }
        }