public override async Task <RequestResult <Guid> > Handle(
            DeleteTenantProviderSettingsCommand request, CancellationToken cancellationToken)
        {
            var tenant = await _tenantProvider.GetTenantAsync(request.TenantCode);

            if (tenant == null)
            {
                return(RequestResult.Failure(ErrorCode.TenantNotFound,
                                             new { request.TenantCode }));
            }

            if (!await _providerSettingsRepository.ProviderSettingsExistsAsync(tenant.Id, request.ProviderType))
            {
                return(RequestResult
                       .Failure(ErrorCode.TenantProviderSettingsNotFound));
            }

            if (!await _providerSettingsRepository
                .RemoveTenantProviderSettings(tenant.Id, request.ProviderType))
            {
                return(RequestResult
                       .Failure(ErrorCode.DeleteTenantProviderSettingsFailed));
            }

            return(RequestResult
                   .Success(request.RequestGuid));
        }
Exemple #2
0
        public override async Task <RequestResult <TenantProviderSettingsDto> > Handle(
            CreateTenantProviderSettingsCommand request, CancellationToken cancellationToken)
        {
            var tenant = await _tenantProvider.GetTenantAsync(request.TenantCode);

            if (tenant == null)
            {
                return(RequestResult <TenantProviderSettingsDto> .Failure(ErrorCode.TenantNotFound,
                                                                          new { request.TenantCode }));
            }

            if (await _providerSettingsRepository.ProviderSettingsExistsAsync(tenant.Id, request.ProviderType))
            {
                return(RequestResult <TenantProviderSettingsDto>
                       .Failure(ErrorCode.TenantProviderSettingsAlreadyExists));
            }

            var createData = _mapper.Map <CreateTenantProviderSettingsData>(request);

            createData.TenantId = tenant.Id;
            var providerSettings = await _providerSettingsRepository
                                   .CreateTenantProviderSettings(createData);

            if (providerSettings == null)
            {
                return(RequestResult <TenantProviderSettingsDto>
                       .Failure(ErrorCode.CreateTenantProviderSettingsFailed));
            }

            return(RequestResult <TenantProviderSettingsDto>
                   .Success(_mapper.Map <TenantProviderSettingsDto>(providerSettings)));
        }