public async Task <ActionResult <StringResult> > Create([FromBody] CreateTenantDto dto) { var createdId = await Task.Run(() => { return(_tenantService.Create(dto)); }); return(Ok(new StringResult { Result = createdId.ToString() })); }
//[Authorize("roles:admin")] public async Task <IActionResult> CreateTenantAsync( [FromBody] CreateTenantCommand command) { try { if (String.IsNullOrEmpty(command.Email)) { return(BadRequest("Email cannot be null or empty.")); } if (!string.IsNullOrEmpty(command.Certificates)) { // Ensure each certificate provided in the command List <string> certificateList = command.Certificates.Split(',').ToList(); foreach (var cert in certificateList) { if (string.IsNullOrEmpty(uploadService.GetFileUri(cert))) { return(BadRequest("At least one certificate name provided is not valid.")); } } } if (command.PhoneNumber == null) { command.PhoneNumber = String.Empty; } if (command.Certificates == null) { command.Certificates = String.Empty; } Enum.TryParse <TenantTypes>(command.Type, true, out TenantTypes tenantType); var result = await tenantService.Create( command.Name, command.Email, command.PrimaryAddress, command.PhoneNumber, command.TaxCode, command.RegistrationCode, command.Certificates, tenantType); return(Ok(new { CompanyId = result })); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex)); } }
public async Task <AppUser> Create(AppUserRegistration model) { var user = _mapper.Map <AppUser>(model); // create tenant var tenant = new Tenant(model.OrganizationName); tenant = await _tenantService.Create(tenant); // assign tenant id to user user.TenantId = tenant.Id; // hash password user.PasswordHash = Encryption.HashPassword(model.Password); await _db.AppUsers.AddAsync(user); await _db.SaveChangesAsync(); return(user); }
public void Create(Tenant tenant) { _tenantService.Create(tenant.Name); }