public async Task <Guid> CreateUser(CreateUserDto input) { var user = input.MapTo <UserEntity>(); var userId = Guid.NewGuid(); user.Id = Guid.NewGuid(); if (!input.Password.IsNullOrEmpty()) { var rs = await new PasswordValidator().ValidateAsync(input.Password); rs.CheckErrors(); } else { input.Password = UserEntity.CreateRandomPassword(); } user.Password = new PasswordHasher().HashPassword(input.Password); if (await _repository.FirstOrDefaultAsync(x => x.UserName == user.UserName) != null) { throw new UserFriendlyException(string.Format(L("Identity.DuplicateName"), user.UserName)); } if (await _repository.FirstOrDefaultAsync(x => x.Email == user.Email) != null) { throw new UserFriendlyException(string.Format(L("Identity.DuplicateEmail"), user.Email)); } if (AbpSession.TenantId.HasValue && AbpSession.TenantId != default(Guid)) { user.TenantId = AbpSession.TenantId.Value; } await _repository.InsertAsync(user); return(user.Id); }