public void addProd() { string ts = "加入购物车失败"; ShoppingCart shopcCart = new ShoppingCart(); shopcCart.ProCode = Request["codes"]; shopcCart.Qty = Convert.ToInt32(Request["num"]); shopcCart.CusId = Convert.ToInt32(Session["cusId"]); shopcCart.CreateTime = DateTime.Now; shopcCart.checks = 0; var shca = ShopCartService.GetEntities(n => n.CusId == shopcCart.CusId && n.ProCode == shopcCart.ProCode); if (shca.Count() > 0) { if (shca.First().Qty + shopcCart.Qty >= 5) { ts = "购物车内该物品数量已达到上限"; return; } shopcCart.Qty += shca.First().Qty; if (ShopCartService.Add(shopcCart)) { ts = "加入购物车成功"; } } else if (ShopCartService.Add(shopcCart)) { ts = "加入购物车成功"; } Response.ContentType = "text/plain"; Response.Write(ts); Response.End(); }
/// <summary> /// 插入购物车 /// </summary> /// <returns></returns> public ActionResult InsertShopCart() { string id = Request["id"]; string price = Request["price"]; string cid = Session["cid"].ToString(); int num = Convert.ToInt32(Request["num"]); Guid g = System.Guid.NewGuid(); //把传过来的商品信息和用户信息添加到数据库 ShoppongCart shoppongCart = new ShoppongCart { Id = g, Cid = cid, Pcode = id, num = num, Price = Convert.ToDecimal(price), Totale = Convert.ToDecimal(price) * num, IsCheck = 0, CreateTime = DateTime.Now }; if (ShopCartService.Add(shoppongCart)) { return(Content("完成添加")); } else { return(Content("未完成添加")); } }
public void addorder() { var ts = 0; var Num = Convert.ToInt32(Request["proNum"]); var Code = Request["proCode"].ToString(); ShoppingCart shopcCart = new ShoppingCart(); shopcCart.ProCode = Code; shopcCart.Qty = Num; shopcCart.CusId = Convert.ToInt32(Session["cusId"]); shopcCart.CreateTime = DateTime.Now; shopcCart.checks = 1; if (Num > ProductService.GetEntity(n => n.Code == Code).Stock.QTY) { ts = 2000; } var shca = ShopCartService.GetEntities(n => n.CusId == shopcCart.CusId && n.ProCode == shopcCart.ProCode); if (shca.Count() > 0) { if (ShopCartService.Add(shopcCart)) { ts = shca.First().Qty; } else { ts = 2000; } } else if (ShopCartService.Add(shopcCart)) { ts = 0; } else { ts = 2000; } Response.ContentType = "text/plain"; Response.Write(ts); Response.End(); }