/// <summary> /// /// </summary> /// <param name="parm"></param> /// <param name="msgType">1 add 0 del</param> /// <returns></returns> public ApiMessage <bool> Add(cart parm) { var api = new ApiMessage <bool>(); var list = _db.Query <cart>(@"SELECT * FROM Cart WHERE UserID=@UserID AND ProductID=@ProductID", parm).ToList(); if (list.Any()) { var node = list.FirstOrDefault(); if (parm.Amount == 0) { node.Delete(); } else { node.Amount = parm.Amount; node.CreatDate = DateTime.Now; node.Update(); } } else { parm.CreatDate = DateTime.Now; parm.ID = Guid.NewGuid().ToString(); parm.Insert(); } api.Msg = "添加成功"; return(api); }