public async Task Add_New_Will_Update_Created_Time(TenantsContext context, Tenant tenant) { tenant.CreatedTime = null; await context.AddAsync(tenant); await context.SaveChangesAsync(); Assert.NotNull(tenant.CreatedTime); }
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); }