Example #1
0
    public async Task <TenantDTO> AddTenantAsync(NewTenantRequest newTenantRequest, string adminId)
    {
        Tenant tenant = newTenantRequest.ToTenant();

        _context.Tenants.Add(tenant);
        await _context.SaveChangesAsync();

        try
        {
            await _permissionService.AddUserPermissionsToTenantAsync(tenant.Id.ToString(), adminId, AppConstants.Roles.TenantAdmin);
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Error setting permission for tenant {tenantName}", newTenantRequest.Name);
            _context.Tenants.Remove(tenant);
            await _context.SaveChangesAsync();

            throw;
        }

        TenantDTO?returnValue = new TenantDTO(tenant);

        return(returnValue);
    }
Example #2
0
    public async Task <IActionResult> PostUserPermissions(string tenantId, string userId, [FromBody] string[] permissions)
    {
        await _permissionService.AddUserPermissionsToTenantAsync(tenantId, userId, permissions);

        return(NoContent());
    }