public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request["action"]; if (action == "edit") { int count = Convert.ToInt32(context.Request["count"]); int cartId = Convert.ToInt32(context.Request["cartId"]); BLL.CartManager cartManager = new BLL.CartManager(); Model.Cart cartModel = cartManager.GetModel(cartId); cartModel.Count = count; cartManager.Update(cartModel); context.Response.Write("ok"); } else if (action == "delete") { int cartId = Convert.ToInt32(context.Request["cartId"]); BLL.CartManager cartManager = new BLL.CartManager(); cartManager.Delete(cartId); context.Response.Write("ok"); } else { context.Response.Write("no"); } }
protected void BindCartList() { BLL.CartManager cartManager = new BLL.CartManager(); List <Model.Cart> list = cartManager.GetModelList("UserId=" + CurrentUser.Id); if (list.Count < 1) { Response.Redirect("/BookList.aspx"); } else { StringBuilder sb = new StringBuilder(); decimal totalMoney = 0; foreach (Model.Cart cartModel in list) { sb.Append("<tr class=\"align_Center\">"); sb.Append("<td style=\"PADDING-BOTTOM: 5px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; PADDING-TOP: 5px\">" + cartModel.Book.Id + "</td>"); sb.Append("<td class=align_Left><a onmouseover=\"\" onmouseout=\"\" onclick=\"\" href='#' target=\"_blank\" >" + cartModel.Book.Title + "</a></td>"); sb.Append("<td><span class=\"price\">¥" + cartModel.Book.UnitPrice.ToString("0.00") + "</span></td>"); sb.Append("<td>" + cartModel.Count + "</td></tr>"); totalMoney = totalMoney + (cartModel.Count * cartModel.Book.UnitPrice); } StrHtml = sb.ToString(); TotalMoney = totalMoney; } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int bookId = Convert.ToInt32(context.Request["bookId"]); //判断一下商品是否存在!! BLL.BookManager bookManager = new BLL.BookManager(); Model.Book bookModel = bookManager.GetModel(bookId); if (bookModel != null) { //判断一下数据库中是否有该商品,如果有,更新数量,没有添加. BLL.CartManager cartManager = new BLL.CartManager(); int userId = ((Model.User)context.Session["userInfo"]).Id; Model.Cart cartModel = cartManager.GetCartModel(bookId, userId); if (cartModel != null) { cartModel.Count = cartModel.Count + 1; cartManager.Update(cartModel); } else { Model.Cart modelCart = new Model.Cart(); modelCart.Count = 1; modelCart.User = (Model.User)context.Session["userInfo"]; modelCart.Book = bookModel; cartManager.Add(modelCart); } context.Response.Write("yes"); } else { context.Response.Write("no"); } }
protected void Page_Load(object sender, EventArgs e) { int userId = ((Model.User)Session["userInfo"]).Id; BLL.CartManager cartManager = new BLL.CartManager(); List <Model.Cart> list = cartManager.GetModelList("UserId=" + userId); CartList = list; }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int cartId = Convert.ToInt32(context.Request["cartId"]); BLL.CartManager cartManager = new BLL.CartManager(); cartManager.Delete(cartId); context.Response.Write("yes"); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //更新购物车中对应商品的数量。 int count = Convert.ToInt32(context.Request["count"]); int cartId = Convert.ToInt32(context.Request["cartId"]); BLL.CartManager cartManager = new BLL.CartManager(); Model.Cart cartModel = cartManager.GetModel(cartId); cartModel.Count = count; cartManager.Update(cartModel); context.Response.Write("ok"); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; BLL.UserManager userManager = new BLL.UserManager(); if (userManager.ValidateUserLogin())//判断是否登录 { int bookId = Convert.ToInt32(context.Request["bookId"]); //判断数据库中是否有该商品. BLL.BookManager bookManager = new BLL.BookManager(); Model.Book bookModel = bookManager.GetModel(bookId); if (bookModel != null) { int userId = ((Model.User)context.Session["userInfo"]).Id;//获取登录用户登录的ID。 BLL.CartManager cartManager = new BLL.CartManager(); Model.Cart cartModel = cartManager.GetModel(userId, bookId); //如果购物车有该商品,更新数量加1,没有插入 if (cartModel != null) { cartModel.Count = cartModel.Count + 1; cartManager.Update(cartModel); } else { Model.Cart modelCart = new Model.Cart(); modelCart.Count = 1; modelCart.Book = bookModel; modelCart.User = ((Model.User)context.Session["userInfo"]); cartManager.Add(modelCart); } context.Response.Write("ok:商品成功添加到购物车"); } else { context.Response.Write("no:无此商品"); } } else { context.Response.Write("login:没有登录"); } }
protected void BindCartList() { BLL.CartManager cartManager = new BLL.CartManager(); CartList = cartManager.GetModelList("UserId=" + ((Model.User)Session["userInfo"]).Id); }