コード例 #1
0
ファイル: AddrDAL.cs プロジェクト: niuhongkui/Portal
 public bool Save(address model)
 {
     if (model.IsDefault == 1)
     {
         _db.Execute("update address set isdefault=0 where userid=@0", model.UserID);
     }
     if (string.IsNullOrEmpty(model.ID))
     {
         model.ID = Guid.NewGuid().ToString();
         model.Insert();
         return(true);
     }
     else
     {
         return(model.Update() > 0);
     }
 }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="parm"></param>
        /// <param name="msgType">1 add 0 del</param>
        /// <returns></returns>
        public ApiMessage <bool> AddOrDel(favorite parm, int msgType)
        {
            var api = new ApiMessage <bool>();

            if (msgType == 1)
            {
                var list = _db.Query <favorite>(@"SELECT * FROM FAVORITE WHERE UserID=@UserID AND ProductID=@ProductID", parm);
                if (list.Any())
                {
                    var node = list.FirstOrDefault();
                    node.Amount    = parm.Amount + node.Amount;
                    node.CreatDate = DateTime.Now;
                    node.Update();
                }
                else
                {
                    parm.CreatDate = DateTime.Now;
                    parm.ID        = Guid.NewGuid().ToString();
                    parm.Insert();
                }
                api.Data = true;
                api.Msg  = "收藏成功";
                return(api);
            }
            else
            {
                var rows = _db.Execute(@"DELETE FROM FAVORITE WHERE UserID=@UserID AND ProductID=@ProductID", parm);
                if (rows > 0)
                {
                    api.Msg = "移除成功";
                }
                else
                {
                    api.Msg     = "移除失败";
                    api.Success = false;
                }
                api.Data = false;
                return(api);
            }
        }