zoukankan      html  css  js  c++  java
  • ABP.NET CORE 框架 取消新增用户邮箱地址必填验证

    1、Core层:  User.cs 实体类中,重写EmailAddress设置可为空类型;

     [Required(AllowEmptyStrings = true)]    //允许空字符串
    public override string EmailAddress { get; set; }

    2、Application层: 还有Dto那边EmailAddress 属性也设置允许可空字符串  ;

    3、Core层: UserManager类中重写 CheckDuplicateUsernameOrEmailAddressAsync 方法

      public override async Task<IdentityResult> CheckDuplicateUsernameOrEmailAddressAsync(long? expectedUserId, string userName, string emailAddress)
            {
                var user = (await FindByNameAsync(userName));
                if (user != null && user.Id != expectedUserId)
                {
                    throw new UserFriendlyException(string.Format(L("Identity.DuplicateUserName"), userName));
                }
    
                if (!string.IsNullOrEmpty(emailAddress))
                {
                    user = (await FindByEmailAsync(emailAddress));
                    if (user != null && user.Id != expectedUserId)
                    {
                        throw new UserFriendlyException(string.Format(L("Identity.DuplicateEmail"), emailAddress));
                    }
                }
    
                return IdentityResult.Success;
            }

    4、EntityFrameworkCore层: 修改Context类  ,插入这段,设置EmailAddress允许为空; 

     protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
                base.OnModelCreating(modelBuilder);
                modelBuilder.Entity<User>().Property(a => a.EmailAddress).IsRequired(false);
      }

    5、 更新数据库:打开程序包管理控制台  输入Add-Migration + 更新内容, 然后输入 Update-DataBase ;

  • 相关阅读:
    从安装.net Core 到helloWord(Mac上)
    阿里云-对象储存OSS
    图片处理
    项目中 添加 swift代码 真机调试 错误
    iOS面试总结
    IOS APP配置.plist汇总
    cocoapods安装问题
    iOS8使用UIVisualEffectView实现模糊效果
    ios键盘回收终极版
    ?C++ 缺少参数的默认参数
  • 原文地址:https://www.cnblogs.com/LinWenQiang/p/13419915.html
Copyright © 2011-2022 走看看