public async Task AddAsync(RegisterModel model) { var cnpjHelper = new CNPJHelper(); await Validate(model.CNPJ, cnpjHelper); model.CNPJ = cnpjHelper.Clean(model.CNPJ); if (await _applicationUserRepository.AnyAsync(x => x.Email.Equals(model.Email))) { throw new CustomExceptions("Este email já está cadatrado"); } using (_unitOfWork) { var id = Guid.NewGuid(); var user = new ApplicationUser { Email = model.Email, UserName = model.Email, CreatedDate = DateTimeOffset.UtcNow, ConcurrencyStamp = Guid.NewGuid().ToString(), EmailConfirmed = true, SecurityStamp = Guid.NewGuid().ToString(), AccessFailedCount = 0, ID = id, Id = id.ToString(), NormalizedUserName = model.Email.ToUpper(), NormalizedEmail = model.Email.ToUpper(), }; var hasher = new PasswordHasher <ApplicationUser>().HashPassword(user, model.Password); user.PasswordHash = hasher; await _applicationUserRepository.AddAsync(user); var company = await _companyRepository.FirstOrDefaultAsync(x => x.CNPJ.Equals(model.CNPJ)); await _userCompanyRepository.AddAsync(new UserCompany { CompanyID = company.ID, UserID = id.ToString() }); await _userManager.AddToRoleAsync(user, "USER"); await _unitOfWork.CommitAsync(); } }