/// <summary> /// 添加购物车 /// </summary> /// <param name="FlowerId"></param> /// <param name="Num"></param> /// <returns></returns> public ActionResult AddToCart(string FlowerId, int Num) { Business.Sys_FlowerShopCart bus = new Business.Sys_FlowerShopCart(); Model.FlowerShopCart Cart = bus.GetFlowerShopCart(FlowerId.ToString(), userid); if (Cart != null) { Cart.Num += Num; Cart.UpdateTime = DateTime.Now; bus.UpdateFlowerShopCart(Cart);//原来有这个商品,更新下数量 } else { Model.FlowerShopCart model = new Model.FlowerShopCart(); model.Num = Num; model.UsersId = userid; model.FlowerId = FlowerId; model.Status = 1; model.CreateTime = DateTime.Now; model.UpdateTime = DateTime.Now; bus.InsertFlowerShopCart(model); } int num = bus.GetFlowerList().Where(m => m.UsersId == userid).ToList().Sum(m => m.Num); return(Json(new { code = 1, cnum = num }, JsonRequestBehavior.AllowGet)); }
public ActionResult IncreaseOrDecreaseOne(string id, int quantity) { Business.Sys_FlowerShopCart bus = new Business.Sys_FlowerShopCart(); Model.FlowerShopCart Cart = bus.GetFlowerShopCartById(id); if (Cart != null) { Cart.Num = quantity; Cart.UpdateTime = DateTime.Now; bus.UpdateFlowerShopCart(Cart);//原来有这个商品,更新下数量 } return(Json(new { msg = true })); }