public async Task <AbpCompany> CreateAsync(AbpCompany companyinput) { if (companyinput == null) { return(null); } var companyData = _repository.FirstOrDefault(c => c.CompanyNo == companyinput.CompanyNo); if (companyData != null) { return(companyData); } else { companyinput.Code = Guid.NewGuid().ToString().Replace("-", "").ToUpper().Substring(0, 12); var data = await _repository.InsertAsync(companyinput); return(data); } }
public async Task <User> RegisterAsync(string name, string phone, string emailAddress, string userName, string plainPassword, bool isEmailConfirmed, AbpCompany companyinput = null) { try { CheckForTenant(); var company = await _companyManager.CreateAsync(companyinput); var tenant = await GetActiveTenantAsync(); var user = new User { TenantId = tenant.Id, Name = name, Surname = "", PhoneNumber = phone, EmailAddress = emailAddress, IsActive = true, UserName = userName, IsEmailConfirmed = isEmailConfirmed, CompanyId = company?.Id.ToString(), Roles = new List <UserRole>() }; user.SetNormalizedNames(); user.Password = _passwordHasher.HashPassword(user, plainPassword); foreach (var defaultRole in await _roleManager.Roles.Where(r => r.IsDefault).ToListAsync()) { user.Roles.Add(new UserRole(tenant.Id, user.Id, defaultRole.Id)); } await _userManager.InitializeOptionsAsync(tenant.Id); CheckErrors(await _userManager.CreateAsync(user, plainPassword)); await CurrentUnitOfWork.SaveChangesAsync(); return(user); } catch (Exception e) { Console.WriteLine(e); throw; } }