Beispiel #1
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <book_shop.Model.CartModel> DataTableToList(DataTable dt)
        {
            List <book_shop.Model.CartModel> modelList = new List <book_shop.Model.CartModel>();
            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                book_shop.Model.CartModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.CartModel();
                    if (dt.Rows[n]["Id"].ToString() != "")
                    {
                        model.Id = int.Parse(dt.Rows[n]["Id"].ToString());
                    }
                    if (dt.Rows[n]["UserId"].ToString() != "")
                    {
                        int UserId = int.Parse(dt.Rows[n]["UserId"].ToString());
                        model.User = userService.GetModel(UserId);
                    }
                    if (dt.Rows[n]["BookId"].ToString() != "")
                    {
                        int BookId = int.Parse(dt.Rows[n]["BookId"].ToString());
                        model.Book = bookService.GetModel(BookId);
                    }
                    if (dt.Rows[n]["Count"].ToString() != "")
                    {
                        model.Count = int.Parse(dt.Rows[n]["Count"].ToString());
                    }

                    modelList.Add(model);
                }
            }
            return(modelList);
        }
Beispiel #2
0
        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");
            }
        }
        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\":\"您还没有登陆\"}");
            }
        }