///<summary>
 /// 用户地址更新
 ///</summary>
 ///<param name="o">UserAddress</param>
 ///<returns></returns>
 public bool UserAddressUpdate(UserAddress o)
 {
     return(Try(nameof(UserAddressUpdate), () =>
     {
         var cmd = SqlBuilder.Update("UserAddress")
                   //.Column("GroupId", o.GroupId)
                   .Column("Consignee", o.Consignee)
                   .Column("CompanyName", o.CompanyName ?? string.Empty)
                   //.Column("CountryId", o.CountryId)
                   .Column("RegionId", o.RegionId)
                   .Column("Province", o.Province)
                   .Column("City", o.City)
                   .Column("District", o.District)
                   .Column("Street", o.Street)
                   .Column("PostalCode", o.PostalCode)
                   .Column("Phone", o.Phone ?? string.Empty)
                   .Column("Mobile", o.Mobile ?? string.Empty)
                   .Column("IsDefault", o.IsDefault)
                   .Column("ModifiedBy", o.ModifiedBy)
                   .Column("ModifiedOn", o.ModifiedOn)
                   .Where("Id=@id and UserId=@userId", new { o.Id, o.UserId })
                   .ToCommand();
         return PassportConn.Execute(cmd) > 0;
     }));
 }
 /// <summary>
 /// 用户图像更新
 /// </summary>
 /// <param name="id">用户id</param>
 /// <param name="avatar">图像url</param>
 /// <returns></returns>
 public bool UserAvatarUpdate(int id, bool avatar)
 {
     return(Try(nameof(UserEmailUpdate), () =>
     {
         var sql = @"update user set avatar=@avatar where id=@id";
         var cmd = SqlBuilder.Raw(sql, new { id, avatar }).ToCommand();
         return PassportConn.Execute(cmd) > 0;
     }));
 }
 /// <summary>
 /// 用户绑定Email更新
 /// </summary>
 /// <param name="id">用户id</param>
 /// <param name="email">有效电子邮箱</param>
 /// <returns></returns>
 public bool UserEmailUpdate(int id, string email)
 {
     return(Try(nameof(UserEmailUpdate), () =>
     {
         var sql = @"update user set email=@email where id=@id";
         var cmd = SqlBuilder.Raw(sql, new { id, email }).ToCommand();
         return PassportConn.Execute(cmd) > 0;
     }));
 }
 /// <summary>
 /// 用户绑定手机号码更新
 /// </summary>
 /// <param name="id">用户id</param>
 /// <param name="mobile">有效手机号码</param>
 /// <returns></returns>
 public bool UserMobileUpdate(int id, string mobile)
 {
     return(Try(nameof(UserMobileUpdate), () =>
     {
         var sql = @"update user set mobile=@mobile where id=@id";
         var cmd = SqlBuilder.Raw(sql, new { id, mobile }).ToCommand();
         return PassportConn.Execute(cmd) > 0;
     }));
 }
 /// <summary>
 /// 用户登录密码更新
 /// </summary>
 /// <param name="id">用户id</param>
 /// <param name="password">登录密码</param>
 /// <returns></returns>
 public bool UserPasswordUpdate(int id, string password)
 {
     return(Try(nameof(UserPasswordUpdate), () =>
     {
         var sql = @"update user set password=@password where id=@id";
         var cmd = SqlBuilder.Raw(sql, new { id, password }).ToCommand();
         return PassportConn.Execute(cmd) > 0;
     }));
 }
        /// <summary>
        /// 用户默认地址设置
        /// </summary>
        /// <param name="id">用户地址id</param>
        /// <param name="userId">用户id</param>
        /// <param name="groupId">地址分组 0为收货地址 2发货地址 3退货地址</param>
        /// <returns></returns>
        public bool UserAddressSetDefault(int id, int userId, byte groupId)
        {
            var sql = @"update UserAddress set IsDefault=0 where UserId=@userId and GroupId=@groupId and Id<>@id;
                        update UserAddress set IsDefault=1 where UserId=@userId and GroupId=@groupId and Id=@id;";

            return(Try(nameof(UserAddressSetDefault), () =>
            {
                var cmd = SqlBuilder.Raw(sql, new { id, userId, groupId }).ToCommand();
                return PassportConn.Execute(cmd) > 0;
            }));
        }
 /// <summary>
 /// 用户地址删除
 /// </summary>
 /// <param name="id">用户地址id</param>
 /// <param name="userId">用户id</param>
 /// <returns></returns>
 public bool UserAddressDelete(int id, int?userId)
 {
     return(Try(nameof(UserAddressDelete), () =>
     {
         var cmd = SqlBuilder.Delete("UserAddress")
                   .Where("Id=@id", new { id })
                   .Where(userId.HasValue, "UserId=@userId", new { userId })
                   .ToCommand();
         return PassportConn.Execute(cmd) > 0;
     }));
 }
 ///<summary>
 /// 用户收藏信息更新
 ///</summary>
 ///<param name="o">用户收藏信息</param>
 ///<returns></returns>
 public bool UserFavoriteUpdate(UserFavorite o)
 {
     return(Try(nameof(UserFavoriteUpdate), () =>
     {
         var cmd = SqlBuilder.Update("UserFavorite")
                   .Column("GroupId", o.GroupId)
                   .Column("Name", o.Name)
                   .Column("Value", o.Value)
                   .Column("Extra", o.Extra)
                   .Column("ModifiedBy", o.ModifiedBy)
                   .Column("ModifiedOn", o.ModifiedOn)
                   .Where("Id=@id and UserId=@userId", new { o.Id, o.UserId })
                   .ToCommand();
         return PassportConn.Execute(cmd) > 0;
     }));
 }
 ///<summary>
 /// 用户发票模版更新
 ///</summary>
 ///<param name="o">用户发票模版</param>
 ///<returns></returns>
 public bool UserInvoiceUpdate(UserInvoice o)
 {
     return(Try(nameof(UserInvoiceUpdate), () =>
     {
         var cmd = SqlBuilder.Update("UserInvoice")
                   .Column("UserId", o.UserId)
                   .Column("GroupId", o.GroupId)
                   .Column("Title", o.Title)
                   .Column("Content", o.Content)
                   .Column("IsDefault", o.IsDefault)
                   .Column("ModifiedBy", o.ModifiedBy)
                   .Column("ModifiedOn", o.ModifiedOn)
                   .Where("Id=@id and UserId=@userId", new { o.Id, o.UserId })
                   .ToCommand();
         return PassportConn.Execute(cmd) > 0;
     }));
 }
 ///<summary>
 /// 用户第三方授权信息更新
 ///</summary>
 ///<param name="o">用户第三方授权信息</param>
 ///<returns></returns>
 public bool UserOAuthUpdate(UserOAuth o)
 {
     return(Try(nameof(UserOAuthUpdate), () =>
     {
         var cmd = SqlBuilder.Update("UserOAuth")
                   .Column("OpenName", o.OpenName)
                   .Column("Scope", o.Scope)
                   .Column("AccessToken", o.AccessToken)
                   .Column("RefreshToken", o.RefreshToken)
                   .Column("ExpiredOn", o.ExpiredOn)
                   .Column("Extra", o.Extra)
                   .Column("ModifiedBy", o.ModifiedBy)
                   .Column("ModifiedOn", o.ModifiedOn)
                   .Where("Id=@id and OpenId=@openId and Provider=@provider", new { o.Id, o.OpenId, o.Provider })
                   .ToCommand();
         return PassportConn.Execute(cmd) > 0;
     }));
 }
 ///<summary>
 /// 用户第三方授权信息创建
 ///</summary>
 ///<param name="o">用户第三方授权信息</param>
 ///<returns></returns>
 public bool UserOAuthCreate(UserOAuth o)
 {
     return(Try(nameof(UserOAuthCreate), () =>
     {
         var cmd = SqlBuilder.Insert("UserOAuth")
                   .Column("Id", o.Id)
                   .Column("OpenId", o.OpenId)
                   .Column("Provider", o.Provider)
                   .Column("OpenName", o.OpenName)
                   .Column("Scope", o.Scope)
                   .Column("AccessToken", o.AccessToken)
                   .Column("RefreshToken", o.RefreshToken)
                   .Column("ExpiredOn", o.ExpiredOn)
                   .Column("Extra", o.Extra)
                   .Column("CreatedOn", o.CreatedOn)
                   .Column("ModifiedBy", o.ModifiedBy)
                   .Column("ModifiedOn", o.ModifiedOn)
                   .ToCommand();
         return PassportConn.Execute(cmd) > 0;
     }));
 }
 ///<summary>
 /// 用户扩展信息更新
 ///</summary>
 ///<param name="o">用户扩展信息</param>
 ///<returns></returns>
 public bool UserProfileUpdate(UserProfile o)
 {
     return(Try(nameof(UserProfileUpdate), () =>
     {
         var cmd = SqlBuilder.Update("UserProfile")
                   .Column("Code", o.Code)
                   .Column("Name", o.Name)
                   .Column("Gender", o.Gender)
                   .Column("Marital", o.Marital)
                   .Column("Birthday", o.Birthday)
                   .Column("Phone", o.Phone)
                   .Column("Mobile", o.Mobile)
                   .Column("RegionId", o.RegionId)
                   .Column("Street", o.Street)
                   .Column("SignUpIp", o.SignUpIp)
                   .Column("SignUpBy", o.SignUpBy)
                   .Column("TraceCode", o.TraceCode)
                   .Column("LastSignInIp", o.LastSignInIp)
                   .Column("LastSignInOn", o.LastSignInOn)
                   .Where("Id=@id", new { o.Id })
                   .ToCommand();
         return PassportConn.Execute(cmd) > 0;
     }));
 }