public override async Task <RequestResult <TenantApplicationDto> > Handle(ApplyForTenantCommand request, CancellationToken cancellationToken) { if (await _tenantsRepository.TenantCodeExists(request.TenantCode)) { return(RequestResult <TenantApplicationDto> .Failure(ErrorCode.TenantAlreadyExistsForCode, new { request.TenantCode })); } var createApplicationData = _mapper.Map <SaveTenantApplicationData>(request); createApplicationData.TenantApplicationGuid = _guid.GetGuid(); var tenantApplication = await _tenantApplicationsRepository .CreateTenantApplication(createApplicationData); return(RequestResult <TenantApplicationDto> .Success(_mapper.Map <TenantApplicationDto>(tenantApplication))); }
public override async Task <RequestResult <TenantDto> > Handle(CreateTenantCommand request, CancellationToken cancellationToken) { if (await _tenantsRepository.TenantCodeExists(request.TenantCode)) { return(RequestResult <TenantDto> .Failure(ErrorCode.TenantAlreadyExistsForCode, new { request.TenantCode })); } var tenant = await _tenantsRepository .CreateTenant(_mapper.Map <CreateTenantData>(request)); if (tenant == null) { return(RequestResult <TenantDto> .Failure(ErrorCode.CreateTenantFailed)); } var saveTenantSettingsData = _mapper.Map <SaveTenantSettingsData>(request); saveTenantSettingsData.TenantId = tenant.Id; var tenantSettings = await _tenantSettingsRepository .SaveTenantSettings(saveTenantSettingsData); if (tenantSettings == null) { return(RequestResult <TenantDto> .Failure(ErrorCode.CreateTenantFailed)); } if (!await _tenantAllowedOriginsRepository .SaveAllowedOriginsAsync(tenant.Id, new List <string> { request.AllowedOrigin })) { return(RequestResult <TenantDto> .Failure(ErrorCode.CreateTenantFailed)); } return(RequestResult <TenantDto> .Success(_mapper.Map <TenantDto>(tenant))); }