public CartSource(UITableView tableView, Model.Cart cart, Action <Model.CartItem> updateCartItem, bool isEdit = true) { _isEdit = isEdit; tableView.RegisterClassForCellReuse(typeof(CartCell), CartCell.CellId); _updateCartItem = updateCartItem; Cart = cart; }
public Model.Cart CreateAndSaveCart(string visitorId) { var cart = new Model.Cart(); cart.VisitorId = visitorId; Save(cart); return cart; }
/// <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("此商品不存在!")); } } }
protected void btnCart_Click(object sender, EventArgs e) { if (Session["user"] == null) { Response.Redirect("./Login.aspx"); } else { int productID = Convert.ToInt32(Request.QueryString["ID"]); int userID = Convert.ToInt32(((User)Session["user"]).UserID.ToString()); int qty = 1; bool isExist = CartRepo.existCartbyProductIdAndUserId(productID, userID); if (isExist == true) { Model.Cart carts = CartRepo.getCartbyProductIdAndUserId(productID, userID); qty = qty + carts.Quantity; CartRepo.updateCart(userID, productID, qty); } else { CartRepo.doInsertProductToCart(userID, productID, qty); } Response.Redirect("./Cart.aspx"); } }
/// <summary> /// 获得数据列表 /// </summary> public List <Model.Cart> DataTableToList(DataTable dt) { List <Model.Cart> modelList = new List <Model.Cart>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { Model.Cart model; for (int n = 0; n < rowsCount; n++) { model = new Model.Cart(); 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 = userServices.GetModel(UserId); } if (dt.Rows[n]["BookId"].ToString() != "") { int BookId = int.Parse(dt.Rows[n]["BookId"].ToString()); model.Book = bookServices.GetModel(BookId); } if (dt.Rows[n]["Count"].ToString() != "") { model.Count = int.Parse(dt.Rows[n]["Count"].ToString()); } modelList.Add(model); } } return(modelList); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.Cart model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Cart("); strSql.Append("UserId,BookId,Count )"); strSql.Append(" values ("); strSql.Append("@UserId,@BookId,@Count)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@BookId", SqlDbType.Int, 4), new SqlParameter("@Count", SqlDbType.Int, 4) } ; parameters[0].Value = model.User.Id; parameters[1].Value = model.Book.Id; parameters[2].Value = model.Count; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
public async Task <IActionResult> Create(Model.Cart cart) { _context.Carts.Add(cart); await _context.SaveChanges(); return(Ok(cart.CartId)); }
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"); } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Model.Cart model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Cart set "); strSql.Append("UserId=@UserId,"); strSql.Append("BookId=@BookId,"); strSql.Append("Count=@Count "); strSql.Append(" where Id=@Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4), new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@BookId", SqlDbType.Int, 4), new SqlParameter("@Count", SqlDbType.Int, 4) }; parameters[0].Value = model.Id; parameters[1].Value = model.User.Id; parameters[2].Value = model.Book.Id; parameters[3].Value = model.Count; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
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"); } }
public static Model.Cart addCart(int userId, int productId, int quantity) { Model.Cart cart = new Model.Cart(); cart.UserId = userId; cart.ProductId = productId; cart.Quantity = quantity; return(cart); }
protected void Button4_Click(object sender, EventArgs e) { int headerID = JSONHelper.Deserializer <int>(htController.getLastHT()); htController.insertHT(headerID, Int32.Parse(userFinish.Text)); Model.Cart currCart = JSONHelper.Deserializer <Model.Cart>(cartController.getUserCart(Int32.Parse(userFinish.Text))); dtController.insertDT(headerID, currCart.Quantity, currCart.ShoeID); }
private HttpResponseMessage Cart(string id, Model.Cart cart) { var response = Request.CreateResponse <Model.Cart>( HttpStatusCode.OK, cart ); return(response); }
public async Task <IActionResult> Post([FromBody] Model.Cart value) { var basket = await _repository.UpdateCartAsync(value); return(Ok(basket)); /*var testbasket = await _repository.CheckPersistency(value); * return Ok(testbasket);*/ }
internal int ProductAddInCart(Model.Cart aCat) { SqlConnection con = new SqlConnection(connection); string query = "INSERT INTO tbl_Cart VALUES('" + aCat.ClientId + "','" + aCat.ProductId + "','" + aCat.Amount + "','" + aCat.DatePurchased + "','" + aCat.IsInCart + "') "; SqlCommand aCommand = new SqlCommand(query, con); con.Open(); int affectedRow = aCommand.ExecuteNonQuery(); con.Close(); return(affectedRow); }
public static void addCart(Model.Cart cart) { Model.Cart validCart = findCart(cart.UserId, cart.ProductId); if (validCart != null) { validCart.Quantity += cart.Quantity; } else { db.Carts.Add(cart); } db.SaveChanges(); }
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"); }
internal string ProductAddInCart(Model.Cart aCat) { int message = aCartGateway.ProductAddInCart(aCat); if (message > 0) { return(" Product successfully added in Shoping Cart"); } else { return("Error!!!! Product not added in Shoping Cart"); } }
protected void updateCart() { userID = Int32.Parse(updateUser.Text); shoeId = Int32.Parse(updateShoe.Text); qty = Int32.Parse(updateQty.Text); string json = cartController.updateCart(userID, shoeId, Int32.Parse(oldQty.Text), qty); Model.Cart cart = JSONHelper.Deserializer <Model.Cart>(json); List <Model.Cart> cartList = new List <Model.Cart>(); cartList.Add(cart); updateCartGrid.DataSource = cartList; updateCartGrid.DataBind(); }
private Model.Cart GetCore(string cartId) { Model.Cart result; var found = _carts.TryGetValue(cartId, out result); if (!found) { result = new Model.Cart(); _carts.Add(cartId, result); } return(result); }
private HttpResponseMessage Cart(string id, Model.Cart cart) { var response = Request.CreateResponse <Model.Cart>( HttpStatusCode.OK, cart ); var cookie = new CookieHeaderValue("cart-id", id); cookie.Expires = DateTimeOffset.Now.AddMinutes(40); cookie.Domain = Request.RequestUri.Host; cookie.Path = "/"; response.Headers.AddCookies(new CookieHeaderValue[] { cookie }); return(response); }
//--------------------------------- /// <summary> /// 根据用户编号与商品的编号,得到一个对象实体 /// </summary> public Model.Cart GetModel(int userId, int bookId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,UserId,BookId,Count from Cart "); strSql.Append(" where UserId=@UserId and BookId=@BookId"); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.Int, 4), new SqlParameter("@BookId", SqlDbType.Int, 4) }; parameters[0].Value = userId; parameters[1].Value = bookId; Model.Cart model = new Model.Cart(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Id"].ToString() != "") { model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); } if (ds.Tables[0].Rows[0]["UserId"].ToString() != "") { int UserId = int.Parse(ds.Tables[0].Rows[0]["UserId"].ToString()); model.User = userServices.GetModel(UserId); } if (ds.Tables[0].Rows[0]["BookId"].ToString() != "") { int BookId = int.Parse(ds.Tables[0].Rows[0]["BookId"].ToString()); model.Book = bookServices.GetModel(BookId); } if (ds.Tables[0].Rows[0]["Count"].ToString() != "") { model.Count = int.Parse(ds.Tables[0].Rows[0]["Count"].ToString()); } return(model); } else { return(null); } }
public static bool addCart(int user_id, int product_id, int quantity) { Model.Cart cartStock = CartRepository.findCart(user_id, product_id); Product addProduct = ProductRepository.findProduct(product_id); int QuantityExist = quantity; if (cartStock != null) { QuantityExist += cartStock.Quantity; } if (QuantityExist <= addProduct.Stock) { Model.Cart cart = CartFactory.addCart(user_id, product_id, quantity); CartRepository.addCart(cart); return(true); } return(false); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; //context.Response.Write("Hello World"); //1.判断用户是否登陆 Model.Users userModel = new BLL.Users().GetModel(context.Request.Cookies["cp1"].Value); if (Common.WebHelper.CheckCookie(userModel) == false) { context.Response.Write("no"); return; } //2.检查该商品数据库中是否存在 int bookId = int.Parse(context.Request["bookId"] ?? "0"); Model.Books book = new BLL.Books().GetModel(bookId); if (book == null) { context.Response.Write("no"); return; } //3.将商品添加到购物车 Model.Users user = (Model.Users)context.Session["userInfo"]; BLL.Cart cartServer = new BLL.Cart(); Model.Cart cart = cartServer.GetCart(user.Id, bookId); if (cart != null) { cart.Count++; cartServer.Update(cart); } else { cart = new Model.Cart(); cart.Count = 1; cart.Book = book; cart.User = user; cartServer.Add(cart); } 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:没有登录"); } }
///// <summary> ///// 得到一个对象实体,重载 ///// </summary> //public Model.Cart GetModel(int bookId,int userId) //{ // StringBuilder strSql = new StringBuilder(); // strSql.Append("select Id,UserId,BookId,Count from Cart where BookId = @BookId and UserId = @UserId"); // SqlParameter[] parameters = { // new SqlParameter("@BookId", SqlDbType.Int,4), // new SqlParameter("@UserId", SqlDbType.Int,4) // }; // parameters[0].Value = bookId; // parameters[1].Value = userId; // Model.Cart model = new Model.Cart(); // DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); // if (ds.Tables[0].Rows.Count > 0) // { // return DataRowToModel(ds.Tables[0].Rows[0]); // } // else // { // return null; // } //} /// <summary> /// 得到一个对象实体 /// </summary> public Model.Cart GetModel2(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,UserId,BookId,Count from Cart "); strSql.Append(" where Id=@Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int,4)}; parameters[0].Value = Id; Model.Cart model = new Model.Cart(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Id"].ToString() != "") { model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString()); } if (ds.Tables[0].Rows[0]["UserId"].ToString() != "") { int UserId = int.Parse(ds.Tables[0].Rows[0]["UserId"].ToString()); model.User = userDal.GetModel(UserId); } if (ds.Tables[0].Rows[0]["BookId"].ToString() != "") { int BookId = int.Parse(ds.Tables[0].Rows[0]["BookId"].ToString()); model.Book = bookDal.GetModel(BookId); } if (ds.Tables[0].Rows[0]["Count"].ToString() != "") { model.Count = int.Parse(ds.Tables[0].Rows[0]["Count"].ToString()); } return model; } else { return null; } }
/// <summary> /// 向购物车中添加商品信息。 /// </summary> protected void AddCart() { if (!string.IsNullOrEmpty(Request.QueryString["id"])) { int bookId = 0; if (!int.TryParse(Request.QueryString["id"], out bookId)) { Response.Redirect("/showinfo.aspx?msg=" + Server.UrlEncode("参数错误") + "&url=BookList.aspx" + "&txt=" + Server.UrlEncode("返回图书列表")); } else { BLL.BookManager bll = new BookShop.BLL.BookManager(); Model.Book model = bll.GetModel(bookId);//根据传递过来的书的编号查找该书. if (model != null) { BLL.CartManager cartBll = new BookShop.BLL.CartManager(); int userId = ((Model.User)Session["user"]).Id; //得到了当前登录用户的编号. Model.Cart cartModel = cartBll.GetModel(model.Id, userId); //根据用户的编号,与书的编号,找出购物车中的商品项. if (cartModel == null) //如果该条件成立,向购物车表中插入一条记录 { Model.Cart ModelCart = new BookShop.Model.Cart(); ModelCart.User = (Model.User)Session["user"]; ModelCart.Book = model; ModelCart.Count = 1; cartBll.Add(ModelCart); } else//更新该商品项的数量 { cartModel.Count = cartModel.Count + 1; cartBll.Update(cartModel); } } else { Response.Redirect("/showinfo.aspx?msg=" + Server.UrlEncode("该书不存在") + "&url=BookList.aspx" + "&txt=" + Server.UrlEncode("返回图书列表")); } } } }
public static List <YF.Model.Cart> Dotolist(DataTable dt) { List <YF.Model.Cart> list = new List <Model.Cart>();//空的泛型对象 转换 for (int i = 0; i < dt.Rows.Count; i++) { YF.Model.Cart cart = new Model.Cart(); // 购物车空对象 cart.Id = int.Parse(dt.Rows[i]["id"].ToString()); //当前商品 YF.Model.Books books = YF.DAL.Books.GetBooks(int.Parse(dt.Rows[i]["bookid"].ToString())); //通过id 得到商品实列对象 //当前用户 YF.Model.User user = YF.DAL.User.Getuser(int.Parse(dt.Rows[i]["userid"].ToString())); //通过id 得到用户实列对象 cart.Books = books; //商品赋值=上面的books cart.User = user; //商品赋值=上面的user cart.Num = int.Parse(dt.Rows[i]["num"].ToString()); cart.State = int.Parse(dt.Rows[i]["state"].ToString()); cart.Adddate = DateTime.Parse(dt.Rows[i]["adddate"].ToString()); list.Add(cart); //空的泛型对象+数据 } return(list); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int bookId = Convert.ToInt32(context.Request.Form["bookId"]); BookManager bookManager = new BookManager(); Book bookModel = bookManager.GetModel(bookId); if (bookModel != null) { User userModel = (User)context.Session["userLogin"]; if (userModel != null) { CartManager cartManager = new CartManager(); Cart cartModel = cartManager.GetModel(userModel.Id, bookId); if (cartModel != null) { cartModel.Count += 1; cartManager.Update(cartModel); } else { Model.Cart modelCart = new Model.Cart(); modelCart.Count = 1; modelCart.Book = bookModel; modelCart.User = userModel; cartManager.Add(modelCart); } context.Response.Write("ok:加入购物车成功"); } } else { context.Response.Write("no:此商品已下架"); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.Cart model) { return(dal.Add(model)); }
/// <summary> /// 根据用户名和密码,登入验证,并且拿cookie的值 /// </summary> /// <param name="loginId">登录名</param> /// <param name="loginPwd">登入密码</param> /// <param name="cookie">cookie</param> /// <param name="msg">返回信息</param> public static void CheckUserLoginPwdAndGetCartCookie(string loginId, string loginPwd, HttpCookie cookie, out string msg) { string rememberMe = HttpContext.Current.Request["RememberMe"] ?? "false"; BLL.UsersBll bll = new BLL.UsersBll(); Model.Users user = new MyBookShop.BLL.UsersBll().GetModelByLoginId(loginId); msg = string.Empty; if (user != null) { msg = Common.CommonTools.GetMd5String(Common.CommonTools.GetMd5String(loginPwd)).Equals(user.LoginPwd) ? "success" : "failed"; } if (msg == "success") { if (rememberMe != "false")//记住我选项 { HttpCookie cookie1 = new HttpCookie("loginId", loginId); cookie1.Value = loginId; cookie1.Expires = DateTime.Now.AddDays(10); HttpContext.Current.Response.Cookies.Add(cookie1); } else { if (cookie != null) { cookie.Expires = DateTime.Now.AddDays(-1); HttpContext.Current.Response.Cookies.Add(cookie); } } //Model.Users user = new BLL.UsersBll().GetModelByLoginId(loginId); HttpContext.Current.Session["userInfo"] = user; //同时检测用户cookie中有没有购物车信息,有就将数据写入数据库 HttpCookie cookieCart = HttpContext.Current.Request.Cookies["ShoppingCart"]; if (cookieCart != null) { int userId = bll.GetModelByLoginId(loginId).Id; foreach (string item in cookieCart.Values) { string itemValue = cookieCart[item].ToString(); string[] cartInfo = itemValue.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); BLL.CartBll cartBll = new BLL.CartBll(); Model.Cart cart = cartBll.GetModel(Convert.ToInt32(cartInfo[0]), user.Id); if (cart == null) { cart = new Model.Cart(); cart.Book.Id = Convert.ToInt32(cartInfo[0]); cart.Count = Convert.ToInt32(cartInfo[1]); cart.User.Id = userId; cartBll.Add2(cart);//调用新的增加方法。对象属性变了 } else { cart.Count += Convert.ToInt32(cartInfo[1]); cartBll.Update2(cart); } } //清空cookie cookieCart.Expires = System.DateTime.Now.AddDays(-1); HttpContext.Current.Response.Cookies.Add(cookieCart); } } }
//添加进购物车 private string AddBookIntoCart(int bookId) { //判断用户是否登入 Model.Users user = Common.CommonTools.CheckIsLoginOrNot(); if (user != null)//登入状态下将数据保存到数据库 { BLL.CartBll bll = new BLL.CartBll(); Model.Cart cart = bll.GetModel(bookId, user.Id); if (cart != null)//先检测购物车中是否存在相同的商品 { cart.Count++;//存在则自增1 bll.Update2(cart);//更新 return "已永久更新你的购物信息"; } else//不存在同样的商品则新增 { cart = new Model.Cart();//为空则创建 cart.Book.Id = bookId; cart.Count = 1; cart.User.Id = user.Id; bll.Add2(cart);//新增 return "已永久新增你的购物信息"; } } else//未登入状态下,保存到cookie { //先判断cookie是否有值 HttpCookie cookie = HttpContext.Current.Request.Cookies["ShoppingCart"]; if (cookie == null) { cookie = new HttpCookie("ShoppingCart"); cookie.Values.Add(bookId.ToString(), bookId + "|" + 1); cookie.Expires = System.DateTime.Now.AddDays(2); HttpContext.Current.Response.Cookies.Add(cookie); return "已临时保存你的购物信息";//,<a href='javascript:LoginClick();'>永久保存?</a> } else { bool flag = true; foreach (string item in cookie.Values) { string itemValue = cookie.Values[item]; if (string.IsNullOrEmpty(itemValue)) { break; } string[] itemValues = itemValue.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (itemValues[0] == bookId.ToString())//如果cookie中存在,则数量增加 { int num = Convert.ToInt32(itemValues[1]) + 1; cookie.Values.Remove(bookId.ToString()); cookie.Values.Add(bookId.ToString(), bookId + "|" + num); cookie.Expires = System.DateTime.Now.AddDays(2); HttpContext.Current.Response.Cookies.Add(cookie); flag = false; break; } } if (flag)//遍历之后都不存在相同产品,则新增一条 { cookie.Values.Add(bookId.ToString(), bookId + "|" + 1); cookie.Expires = System.DateTime.Now.AddDays(2); HttpContext.Current.Response.Cookies.Add(cookie); } return "已临时更新你的购物信息";//,<a href='javascript:LoginClick();'>永久保存?</a> } } }
public void ProcessRequest(HttpContext context) { if (!string.IsNullOrEmpty(context.Request.Form["action"])) { string action = context.Request.Form["action"]; if (action == "change")//更新商品数量 { int pk, bookId, count; if (!int.TryParse(context.Request.Form["pk"], out pk)) { context.Response.Write("no-参数错误!"); return; } if (!int.TryParse(context.Request.Form["count"], out count)) { context.Response.Write("no-参数错误!"); return; } if (!int.TryParse(context.Request.Form["bookId"], out bookId)) { context.Response.Write("no-参数错误!"); return; } BLL.BookManager bookBll = new BookShop.BLL.BookManager(); Model.Book modelBook = bookBll.GetModel(bookId); if (modelBook != null)//看一下该书是否存在 { BLL.CartManager cartBll = new BookShop.BLL.CartManager(); Model.Cart cartModel = cartBll.GetModel(pk); if (cartModel != null)//根据主键查找该购物车中商品项 { cartModel.Count = count; cartBll.Update(cartModel);//完成数量的更新 context.Response.Write("yes"); } else { context.Response.Write("no"); return; } } else { context.Response.Write("no"); } } //删除一条记录 else if (action == "delete") { if (!string.IsNullOrEmpty(context.Request.Form["pk"])) { int pkId = 0; if (!int.TryParse(context.Request.Form["pk"], out pkId)) { context.Response.Write("no"); return; } BLL.CartManager bllCart = new BookShop.BLL.CartManager(); bllCart.Delete(pkId); context.Response.Write("yes"); } } } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Model.Cart model) { dal.Update(model); }
public static void deleteCart(int cart_id) { Model.Cart deleteCart = findByCartId(cart_id); db.Carts.Remove(deleteCart); db.SaveChanges(); }
public static void InitTestDBContext(ECAEntities @this) { using (SpreadsheetDocument mySpreadsheet = SpreadsheetDocument.Open(@"../../TestData.xlsx", false)) { var sheets = mySpreadsheet.WorkbookPart.Workbook.Sheets; SharedStringTable stringTable = mySpreadsheet.WorkbookPart.SharedStringTablePart.SharedStringTable; //Author Sheet sAuthor = sheets.Descendants<Sheet>().Where(s => s.Name == "Author").FirstOrDefault(); WorksheetPart wsPart = mySpreadsheet.WorkbookPart.GetPartById(sAuthor.Id) as WorksheetPart; SheetData sheetData = wsPart.Worksheet.Elements<SheetData>().First(); @this.Authors = new FakeDbSet<Model.Author>(); foreach (Row r in sheetData.Elements<Row>()) { if (r.RowIndex == 1) continue; ECA.Model.Author author = new Model.Author(); author.AuthorId = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(0), 0); author.AuthorName = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(1), 1); @this.Authors.Add(author); } //Book Sheet sBook = sheets.Descendants<Sheet>().Where(s => s.Name == "Book").FirstOrDefault(); wsPart = mySpreadsheet.WorkbookPart.GetPartById(sBook.Id) as WorksheetPart; sheetData = wsPart.Worksheet.Elements<SheetData>().First(); @this.Books = new FakeDbSet<Model.Book>(); foreach (Row r in sheetData.Elements<Row>()) { if (r.RowIndex == 1) continue; ECA.Model.Book book = new Model.Book(); book.ID = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(0), 0); book.Title = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(1), 1); book.Description = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(2), 2); book.AuthorId = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(3), 3); book.GenreId = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(4), 4); book.CategoryId = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(5), 5); book.ISBN = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(6), 6); @this.Books.Add(book); } //Book Category Sheet sBookCategory = sheets.Descendants<Sheet>().Where(s => s.Name == "BookCategory").FirstOrDefault(); wsPart = mySpreadsheet.WorkbookPart.GetPartById(sBookCategory.Id) as WorksheetPart; sheetData = wsPart.Worksheet.Elements<SheetData>().First(); @this.BookCategories = new FakeDbSet<Model.BookCategory>(); foreach (Row r in sheetData.Elements<Row>()) { if (r.RowIndex == 1) continue; ECA.Model.BookCategory category = new Model.BookCategory(); category.CategoryId = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(0), 0); category.CategoryName = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(1), 1); @this.BookCategories.Add(category); } //Genre Sheet sGenre = sheets.Descendants<Sheet>().Where(s => s.Name == "Genre").FirstOrDefault(); wsPart = mySpreadsheet.WorkbookPart.GetPartById(sGenre.Id) as WorksheetPart; sheetData = wsPart.Worksheet.Elements<SheetData>().First(); @this.Genres = new FakeDbSet<Model.Genre>(); foreach (Row r in sheetData.Elements<Row>()) { if (r.RowIndex == 1) continue; ECA.Model.Genre genre = new Model.Genre(); genre.GenreId = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(0), 0); genre.GenreName = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(1), 1); @this.Genres.Add(genre); } //Shopping Cart Sheet sCart = sheets.Descendants<Sheet>().Where(s => s.Name == "Cart").FirstOrDefault(); wsPart = mySpreadsheet.WorkbookPart.GetPartById(sCart.Id) as WorksheetPart; sheetData = wsPart.Worksheet.Elements<SheetData>().First(); @this.Carts = new FakeDbSet<Model.Cart>(); foreach (Row r in sheetData.Elements<Row>()) { if (r.RowIndex == 1) continue; ECA.Model.Cart cart = new Model.Cart(); cart.UserId = Convert.ToInt32( r.Elements<Cell>().ElementAt(0).CellValue.Text); cart.ItemCode = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(1), 1); cart.Quantity = Convert.ToInt32(r.Elements<Cell>().ElementAt(2).CellValue.Text); @this.Carts.Add(cart); } //Users Sheet sUser = sheets.Descendants<Sheet>().Where(s => s.Name == "User").FirstOrDefault(); wsPart = mySpreadsheet.WorkbookPart.GetPartById(sUser.Id) as WorksheetPart; sheetData = wsPart.Worksheet.Elements<SheetData>().First(); @this.Users = new FakeDbSet<Model.User>(); foreach (Row r in sheetData.Elements<Row>()) { if (r.RowIndex == 1) continue; ECA.Model.User user = new Model.User(); user.UserId = Convert.ToInt32(r.Elements<Cell>().ElementAt(0).CellValue.Text); user.UserName = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(1), 1); @this.Users.Add(user); } //Roles Sheet sRoles = sheets.Descendants<Sheet>().Where(s => s.Name == "Role").FirstOrDefault(); wsPart = mySpreadsheet.WorkbookPart.GetPartById(sRoles.Id) as WorksheetPart; sheetData = wsPart.Worksheet.Elements<SheetData>().First(); @this.webpages_Roles = new FakeDbSet<Model.webpages_Roles>(); foreach (Row r in sheetData.Elements<Row>()) { if (r.RowIndex == 1) continue; ECA.Model.webpages_Roles role = new Model.webpages_Roles(); role.RoleId = Convert.ToInt32(r.Elements<Cell>().ElementAt(0).CellValue.Text); role.RoleName = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(1), 1); @this.webpages_Roles.Add(role); } @this.webpages_Roles.Where(r => r.RoleId == 1).FirstOrDefault().Users = new List<User>() { new User(){ UserId = 1, UserName = "******"}, new User(){ UserId = 2,UserName = "******"} }; @this.webpages_Roles.Where(r => r.RoleId == 2).FirstOrDefault().Users = new List<User>() { new User(){ UserId = 3, UserName = "******"} }; //Membership Sheet sMembership = sheets.Descendants<Sheet>().Where(s => s.Name == "Membership").FirstOrDefault(); wsPart = mySpreadsheet.WorkbookPart.GetPartById(sMembership.Id) as WorksheetPart; sheetData = wsPart.Worksheet.Elements<SheetData>().First(); @this.webpages_Membership = new FakeDbSet<Model.webpages_Membership>(); foreach (Row r in sheetData.Elements<Row>()) { if (r.RowIndex == 1) continue; ECA.Model.webpages_Membership membership = new Model.webpages_Membership(); membership.UserId = Convert.ToInt32(r.Elements<Cell>().ElementAt(0).CellValue.Text); membership.Password = GetStringValue(stringTable, r.Elements<Cell>().ElementAt(6), 6); @this.webpages_Membership.Add(membership); } } }