private async Task <CreateApplicationRequest> BuildRequest(StartApplicationRequest startApplicationRequest, string applicationType, Guid contactId, Guid organisationId, string referenceFormat)
        {
            var qnaResponse = await _qnaApiClient.StartApplications(startApplicationRequest);

            var sequences = await _qnaApiClient.GetAllApplicationSequences(qnaResponse.ApplicationId);

            var sections = sequences.Select(async sequence => await _qnaApiClient.GetSections(qnaResponse.ApplicationId, sequence.Id)).Select(t => t.Result).ToList();

            return(new CreateApplicationRequest
            {
                ApplicationType = applicationType,
                QnaApplicationId = qnaResponse.ApplicationId,
                OrganisationId = organisationId,
                ApplicationReferenceFormat = referenceFormat,
                CreatingContactId = contactId,
                ApplySequences = sequences.Select(sequence => new ApplySequence
                {
                    SequenceId = sequence.Id,
                    Sections = sections.SelectMany(y => y.Where(x => x.SequenceNo == sequence.SequenceNo).Select(x => new ApplySection
                    {
                        SectionId = x.Id,
                        SectionNo = x.SectionNo,
                        Status = ApplicationSectionStatus.Draft,
                        RequestedFeedbackAnswered = x.QnAData.RequestedFeedbackAnswered
                    })).ToList(),
                    Status = ApplicationSequenceStatus.Draft,
                    IsActive = sequence.IsActive,
                    SequenceNo = sequence.SequenceNo,
                    NotRequired = sequence.NotRequired
                }).ToList()
            });
        }
        public async Task AugmentModelWithModerationFailDetails(ApplicationSummaryWithModeratorDetailsViewModel model, string userId)
        {
            var sequences = await _apiClient.GetClarificationSequences(model.ApplicationId);

            var passFailDetails = await _apiClient.GetAllClarificationPageReviewOutcomes(model.ApplicationId, userId);

            var moderationFailedDetails = passFailDetails?.Where(x => x.Status == ModerationStatus.Fail ||
                                                                 (x.Status == null && x.ModeratorReviewStatus == ModerationStatus.Fail)).ToList();

            if (moderationFailedDetails.Any())
            {
                AddPagesToSequencesFromFailedDetails(sequences, moderationFailedDetails);

                var sequencesWithModerationFails = new List <AssessorSequence>();
                BuildSequencesWithModerationFails(sequences, sequencesWithModerationFails);

                var allSections = await _qnaApiClient.GetSections(model.ApplicationId);

                RemoveInactiveOrEmptyPagesSectionsSequencesFromSequences(sequencesWithModerationFails, allSections);
                AddPageTitlesToSequences(sequencesWithModerationFails);
                AddAnswersToSequences(sequencesWithModerationFails, allSections);
                AddQuestionsToSequences(sequencesWithModerationFails, allSections);
                AddSequenceTitlesToSequences(sequencesWithModerationFails);
                model.Sequences         = sequencesWithModerationFails;
                model.PagesWithGuidance =
                    GatherGuidancePagesForSequenceQuestions(sequencesWithModerationFails, allSections);
                model.PagesWithClarifications = GatherClarificationPages(moderationFailedDetails);
            }
        }
        public async Task <IActionResult> ActiveSequence(Guid applicationId, BackViewModel backViewModel)
        {
            var application = await _applyApiClient.GetApplication(applicationId);

            var organisation = await _apiClient.GetOrganisation(application.OrganisationId);

            var activeApplySequence = application.ApplyData.Sequences.Where(seq => seq.IsActive && !seq.NotRequired).OrderBy(seq => seq.SequenceNo).FirstOrDefault();

            var sequence = await _qnaApiClient.GetSequence(application.ApplicationId, activeApplySequence.SequenceId);

            var sections = await _qnaApiClient.GetSections(application.ApplicationId, sequence.Id);

            var sequenceVm = new SequenceViewModel(application, organisation, sequence, sections,
                                                   activeApplySequence.Sections,
                                                   backViewModel.BackAction,
                                                   backViewModel.BackController,
                                                   backViewModel.BackOrganisationId);

            return(View(nameof(Sequence), sequenceVm));
        }
示例#4
0
        private async Task <List <Section> > GetFinancialSections(RoatpApply applicationFromAssessor)
        {
            const string CompanyFhaSectionTitle       = "Organisation's financial health";
            const string ParentCompanyFhaSectionTitle = "UK ultimate parent company's financial health";

            var financialSections = new List <Section>();

            var applicationId        = applicationFromAssessor.ApplicationId;
            var applicationSequences = applicationFromAssessor.ApplyData?.Sequences;

            var roatpSequences = await _applyApiClient.GetRoatpSequences();

            var financialSequences = roatpSequences.Where(x => x.Roles.Contains(Roles.ProviderRiskAssuranceTeam));

            foreach (var sequence in financialSequences)
            {
                var qnaSequence = await _qnaApiClient.GetSequenceBySequenceNo(applicationId, sequence.Id);

                var qnaSections = await _qnaApiClient.GetSections(applicationId, qnaSequence.Id);

                foreach (var section in qnaSections)
                {
                    var roatpSequence = roatpSequences.FirstOrDefault(x => x.Id == sequence.Id);

                    if (!roatpSequence.ExcludeSections.Contains(section.SectionNo.ToString()) && IsRequiredSection(applicationSequences, section))
                    {
                        // Ensure at least one active page is answered
                        if (section.QnAData.Pages.Any(p => p.Active && p.Complete))
                        {
                            // APR-1477 - adjust title for Assessor
                            if (section.SequenceNo == RoatpQnaConstants.RoatpSequences.FinancialEvidence && section.SectionNo == RoatpQnaConstants.RoatpSections.FinancialEvidence.YourOrganisationsFinancialEvidence)
                            {
                                section.LinkTitle = CompanyFhaSectionTitle;
                                section.Title     = CompanyFhaSectionTitle;
                            }
                            else if (section.SequenceNo == RoatpQnaConstants.RoatpSequences.FinancialEvidence && section.SectionNo == RoatpQnaConstants.RoatpSections.FinancialEvidence.YourUkUltimateParentCompanysFinancialEvidence)
                            {
                                section.LinkTitle = ParentCompanyFhaSectionTitle;
                                section.Title     = ParentCompanyFhaSectionTitle;
                            }

                            // APR-1606 - Display in PageId order
                            section.QnAData.Pages = section.QnAData.Pages.OrderBy(p => p.PageId).ToList();

                            financialSections.Add(section);
                        }
                    }
                }
            }

            return(financialSections);
        }
示例#5
0
        public async Task <IActionResult> StartApplication(PreviewViewModel previewViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(previewViewModel));
            }

            var applicationStartRequest = new StartApplicationRequest
            {
                UserReference   = UserReference,
                WorkflowType    = previewViewModel.ProjectType,
                ApplicationData = previewViewModel.ApplicationData
            };

            var qnaResponse = new StartApplicationResponse();

            try
            {
                qnaResponse = await _qnaApiClient.StartApplications(applicationStartRequest);
            }
            catch (HttpRequestException ex) {
                dynamic obj = JToken.Parse(ex.Message);
                if (obj.statusCode == "400")
                {
                    ModelState.AddModelError(nameof(previewViewModel.ApplicationData), (string)obj.message);
                    return(View(previewViewModel));
                }
            }

            if (_sessionService.Exists("viewPreviewData"))
            {
                _sessionService.Remove("viewPreviewData");
            }
            _sessionService.Set("viewPreviewData", JsonConvert.SerializeObject(previewViewModel));

            var allApplicationSequences = await _qnaApiClient.GetAllApplicationSequences(qnaResponse.ApplicationId);

            var sequenceNos = string.Join(',', allApplicationSequences.Select(x => x.SequenceNo));

            foreach (var _ in allApplicationSequences.Where(seq => seq.SequenceNo == previewViewModel.SequenceNo).Select(seq => new { }))
            {
                var sections = allApplicationSequences.Select(async sequence => await _qnaApiClient.GetSections(qnaResponse.ApplicationId, sequence.Id)).Select(t => t.Result).ToList();
                return(RedirectToAction("Sequence", new { Id = qnaResponse.ApplicationId, sequenceNo = previewViewModel.SequenceNo }));
            }

            ModelState.AddModelError(nameof(previewViewModel.SequenceNo), $"Sequence number not found. Valid sequences are: {sequenceNos}");
            return(View(previewViewModel));
        }
示例#6
0
        public async Task <IEnumerable <ApplicationSequence> > GetApplicationSequences(Guid applicationId)
        {
            var sequencesTask = _qnaApiClient.GetSequences(applicationId);
            var sectionsTask  = _qnaApiClient.GetSections(applicationId);

            await Task.WhenAll(sequencesTask, sectionsTask);

            var sequences = await sequencesTask;
            var sections  = await sectionsTask;

            PopulateAdditionalSequenceFields(sequences);

            var filteredSequences = sequences.Where(x => x.SequenceId != RoatpWorkflowSequenceIds.Preamble && x.SequenceId != RoatpWorkflowSequenceIds.ConditionsOfAcceptance).OrderBy(y => y.SequenceId);

            foreach (var sequence in filteredSequences)
            {
                sequence.Sections = new List <ApplicationSection>(sections.Where(sec => sec.SequenceId == sequence.SequenceId));
            }

            return(filteredSequences.ToList());
        }