/// <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 GetTotal() { Business.Sys_FlowerShopCart bus = new Business.Sys_FlowerShopCart(); List <Model.FlowerShopCart> list = bus.GetFlowerList().Where(m => m.UsersId == userid).ToList(); int num = list.Sum(p => p.Num); return(Json(new { code = 1, cnum = num }, JsonRequestBehavior.AllowGet)); }