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()
            });
        }
Esempio n. 2
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));
        }
Esempio n. 3
0
        public async Task <IActionResult> PerformSnapshot(SnapshotViewModel vm)
        {
            if (_configuration["EnvironmentName"].EndsWith("PROD", StringComparison.InvariantCultureIgnoreCase))
            {
                return(RedirectToAction("Index", "Dashboard"));
            }

            var application = await _applyApiClient.GetApplication(vm.ApplicationId ?? Guid.NewGuid());

            if (vm.ApplicationId is null)
            {
                ModelState.AddModelError("ApplicationId", "Please enter Application Id");
            }
            else if (application is null)
            {
                ModelState.AddModelError("ApplicationId", "Application not found");
            }

            if (ModelState.IsValid)
            {
                var snapshotResponse = await _qnaApiClient.SnapshotApplication(application.ApplicationId);

                var allSnapshotSequences = await _qnaApiClient.GetAllApplicationSequences(snapshotResponse.ApplicationId);

                var allSnapshotSections = await _qnaApiClient.GetAllApplicationSections(snapshotResponse.ApplicationId);

                var applySequences = application.ApplyData.Sequences;

                // must update all ids!
                foreach (var sequence in applySequences)
                {
                    var snapshotSequence = allSnapshotSequences.FirstOrDefault(seq => seq.SequenceNo == sequence.SequenceNo);
                    if (snapshotSequence != null)
                    {
                        sequence.SequenceId = snapshotSequence.Id;

                        foreach (var section in sequence.Sections)
                        {
                            var snapshotSection = allSnapshotSections.FirstOrDefault(sec => sec.SequenceNo == sequence.SequenceNo && sec.SectionNo == section.SectionNo);

                            if (snapshotSection != null)
                            {
                                section.SectionId = snapshotSection.Id;
                            }
                        }
                    }
                }

                var applySnapshotResponse = await _applyApiClient.SnapshotApplication(application.ApplicationId, snapshotResponse.ApplicationId, applySequences);

                if (applySnapshotResponse != Guid.Empty)
                {
                    vm.SnapshotApplicationId = applySnapshotResponse;
                    vm.SnapshotSuccessful    = true;
                }
                else
                {
                    vm.SnapshotSuccessful = false;
                }
            }

            return(View("~/Views/Roatp/Apply/Snapshot/Index.cshtml", vm));
        }