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 ;

  • 相关阅读:
    Docker 入门
    python3模块: sys
    Python sys os getpass 包的导入
    Python3模块: hashlib
    python3异常处理 try
    python3模块: uuid
    python3 内置函数详解
    servlet/和/*匹配的区别
    [转]任何程序员应该记住的性能指标
    [转]使用CMS垃圾收集器产生的问题和解决方案
  • 原文地址:https://www.cnblogs.com/LinWenQiang/p/13419915.html
Copyright © 2011-2022 走看看