public async Task <OutcomeViewModel> GetOversightDetailsViewModel(Guid applicationId, Guid?outcomeKey)
        {
            var applicationDetailsTask = _applyApiClient.GetApplicationDetails(applicationId);
            var oversightReviewTask    = _applyApiClient.GetOversightReview(applicationId);
            await Task.WhenAll(applicationDetailsTask, oversightReviewTask);

            var applicationDetails = _applyApiClient.GetApplicationDetails(applicationId).Result;
            var oversightReview    = _applyApiClient.GetOversightReview(applicationId).Result;

            GetAppealResponse appealResponse = null;

            if (oversightReview != null)
            {
                appealResponse = await _applyApiClient.GetAppeal(applicationId, oversightReview.Id);
            }

            var viewModel = new OutcomeViewModel
            {
                IsNew = oversightReview == null,
                ApplicationSummary     = CreateApplicationSummaryViewModel(applicationDetails),
                GatewayOutcome         = CreateGatewayOutcomeViewModel(applicationDetails, oversightReview),
                FinancialHealthOutcome = CreateFinancialHealthOutcomeViewModel(applicationDetails),
                ModerationOutcome      = CreateModerationOutcomeViewModel(applicationDetails, oversightReview),
                InProgressDetails      = CreateInProgressDetailsViewModel(oversightReview),
                OverallOutcome         = CreateOverallOutcomeViewModel(oversightReview),
                AppealViewModel        = appealResponse == null ? null : CreateAppealViewModel(applicationDetails, appealResponse),
                ShowAppealLink         = oversightReview != null && oversightReview.Status == OversightReviewStatus.Unsuccessful && appealResponse == null,
                ShowInProgressDetails  = oversightReview?.InProgressDate != null,
                OversightStatus        = oversightReview?.Status ?? OversightReviewStatus.None,
                ApproveGateway         = GetStringValueForApprovalStatusBoolean(oversightReview?.GatewayApproved),
                ApproveModeration      = GetStringValueForApprovalStatusBoolean(oversightReview?.ModerationApproved),
                IsGatewayRemoved       = applicationDetails.ApplicationStatus == ApplicationStatus.Removed,
                IsGatewayFail          = applicationDetails.GatewayReviewStatus == GatewayReviewStatus.Fail,
                HasFinalOutcome        = oversightReview != null && oversightReview.Status != OversightReviewStatus.None && oversightReview.Status != OversightReviewStatus.InProgress
            };

            if (oversightReview == null || oversightReview.Status == OversightReviewStatus.InProgress)
            {
                var cachedItem = await _cacheStorageService.RetrieveFromCache <OutcomePostRequest>(outcomeKey.ToString());

                if (cachedItem == null)
                {
                    return(viewModel);
                }

                viewModel.OversightStatus                 = cachedItem.OversightStatus;
                viewModel.ApproveGateway                  = cachedItem.ApproveGateway;
                viewModel.ApproveModeration               = cachedItem.ApproveModeration;
                viewModel.SuccessfulText                  = cachedItem.SuccessfulText;
                viewModel.SuccessfulAlreadyActiveText     = cachedItem.SuccessfulAlreadyActiveText;
                viewModel.SuccessfulFitnessForFundingText = cachedItem.SuccessfulFitnessForFundingText;
                viewModel.UnsuccessfulText                = cachedItem.UnsuccessfulText;
                viewModel.UnsuccessfulExternalText        = cachedItem.UnsuccessfulExternalText;
                viewModel.InProgressInternalText          = cachedItem.InProgressInternalText;
                viewModel.InProgressExternalText          = cachedItem.InProgressExternalText;
            }

            return(viewModel);
        }
예제 #2
0
        private async Task <bool> RecordInRoatp(Guid applicationId, string appealStatus, string userId, string userName,
                                                OrganisationRegisterStatus registerStatus, RoatpRegistrationDetails registrationDetails)
        {
            var application = await _applicationApiClient.GetApplicationDetails(applicationId);

            if (application.GatewayReviewStatus != GatewayReviewStatus.Fail)
            {
                if (registerStatus?.OrganisationId != null && (appealStatus == AppealStatus.SuccessfulAlreadyActive ||
                                                               appealStatus == AppealStatus.SuccessfulFitnessForFunding))
                {
                    var updateOrganisationRequest = new UpdateOrganisationRequest
                    {
                        ApplicationDeterminedDate = DateTime.UtcNow.Date,
                        LegalName          = registrationDetails.LegalName,
                        OrganisationId     = registerStatus.OrganisationId.Value,
                        Username           = userName,
                        CharityNumber      = registrationDetails.CharityNumber,
                        CompanyNumber      = registrationDetails.CompanyNumber,
                        OrganisationTypeId = registrationDetails.OrganisationTypeId,
                        ProviderTypeId     = registrationDetails.ProviderTypeId,
                        TradingName        = registrationDetails.TradingName,
                    };

                    _logger.LogInformation($"Updating organisation details for application {applicationId}");

                    return(await _registerApiClient.UpdateOrganisation(updateOrganisationRequest));
                }

                if (appealStatus == AppealStatus.Successful)
                {
                    var request = BuildCreateOrganisationRequest(userName, registrationDetails);

                    return(await _registerApiClient.CreateOrganisation(request));
                }
            }
            return(true);
        }