Ejemplo n.º 1
0
        private async Task UpdatePageAnswersBySectionNo(SelectApplicationRouteViewModel model)
        {
            var preambleDetails = await _qnaApiClient.GetPageBySectionNo(model.ApplicationId,
                                                                         RoatpWorkflowSequenceIds.Preamble, RoatpWorkflowSectionIds.Preamble, RoatpWorkflowPageIds.Preamble);

            var preambleAnswers = preambleDetails?.PageOfAnswers[0]?.Answers;

            var onRoatp =
                await _qnaApiClient.GetAnswerByTag(model.ApplicationId, RoatpWorkflowQuestionTags.OnRoatp);

            var onRoatpRegisterTrue = onRoatp?.Value == "TRUE";
            var routeAndOnRoatp     = string.Empty;

            switch (model.ApplicationRouteId)
            {
            case ApplicationRoute.MainProviderApplicationRoute:
                routeAndOnRoatp = onRoatpRegisterTrue
                        ? RouteAndOnRoatpTags.MainOnRoatp
                        : RouteAndOnRoatpTags.MainNotOnRoatp;
                break;

            case ApplicationRoute.EmployerProviderApplicationRoute:
                routeAndOnRoatp = onRoatpRegisterTrue
                        ? RouteAndOnRoatpTags.EmployerOnRoatp
                        : RouteAndOnRoatpTags.EmployerNotOnRoatp;
                break;

            case ApplicationRoute.SupportingProviderApplicationRoute:
                routeAndOnRoatp = onRoatpRegisterTrue
                        ? RouteAndOnRoatpTags.SupportingOnRoatp
                        : RouteAndOnRoatpTags.SupportingNotOnRoatp;
                break;
            }

            if (preambleAnswers != null)
            {
                foreach (var answer in preambleAnswers.Where(ans => ans.QuestionId == RoatpPreambleQuestionIdConstants.RouteAndOnRoatp))
                {
                    answer.Value = routeAndOnRoatp;
                }

                await _qnaApiClient.UpdatePageAnswers(model.ApplicationId, RoatpWorkflowSequenceIds.Preamble,
                                                      RoatpWorkflowSectionIds.Preamble, RoatpWorkflowPageIds.Preamble, preambleAnswers);
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Page(Guid Id, int sequenceNo, int sectionNo, string pageId, string __redirectAction, string __summaryLink = "Show")
        {
            var sequence = await _qnaApiClient.GetSequenceBySequenceNo(Id, sequenceNo);

            var section = await _qnaApiClient.GetSectionBySectionNo(Id, sequenceNo, sectionNo);

            PageViewModel viewModel   = null;
            var           returnUrl   = Request.Headers["Referer"].ToString();
            var           pageContext = OrganisationName;

            if (!ModelState.IsValid)
            {
                var page = JsonConvert.DeserializeObject <Page>((string)TempData["InvalidPage"]);
                page = GetDataFedOptions(page);

                var errorMessages = !ModelState.IsValid
                    ? ModelState.SelectMany(k => k.Value.Errors.Select(e => new ValidationErrorDetail()
                {
                    ErrorMessage = e.ErrorMessage,
                    Field        = k.Key
                })).ToList()
                    : null;

                if (page.ShowTitleAsCaption)
                {
                    page.Title = section.Title;
                }

                UpdateValidationDetailsForAddress(page, errorMessages);
                viewModel = new PageViewModel(Id, sequenceNo, sectionNo, pageId, page, pageContext, __redirectAction,
                                              returnUrl, errorMessages, __summaryLink);
            }
            else
            {
                try
                {
                    var page = await _qnaApiClient.GetPageBySectionNo(Id, sequenceNo, sectionNo, pageId);

                    if (page != null && (!page.Active))
                    {
                        var nextPage = page.Next.FirstOrDefault(p => p.Conditions is null || p.Conditions.Count == 0);

                        if (nextPage?.ReturnId != null && nextPage?.Action == "NextPage")
                        {
                            pageId = nextPage.ReturnId;
                            return(RedirectToAction("Page",
                                                    new { Id, sequenceNo, sectionNo, pageId, __redirectAction }));
                        }
                        else
                        {
                            return(RedirectToAction("Section", new { Id, sequenceNo, sectionNo }));
                        }
                    }

                    page = GetDataFedOptions(page);

                    if (page.ShowTitleAsCaption)
                    {
                        page.Title = section.Title;
                    }

                    viewModel = new PageViewModel(Id, sequenceNo, sectionNo, page.PageId, page, pageContext, __redirectAction,
                                                  returnUrl, null, __summaryLink);
                }
                catch (Exception ex)
                {
                    if (ex.Message.Equals("Could not find the page", StringComparison.OrdinalIgnoreCase))
                    {
                        return(RedirectToAction("Applications"));
                    }
                    throw ex;
                }
            }

            var applicationData = await _qnaApiClient.GetApplicationDataDictionary(Id);

            ReplaceApplicationDataPropertyPlaceholdersInQuestions(viewModel.Questions, applicationData);

            if (viewModel.AllowMultipleAnswers)
            {
                return(View("~/Views/Application/Pages/MultipleAnswers.cshtml", viewModel));
            }

            return(View("~/Views/Application/Pages/Index.cshtml", viewModel));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Index(Guid?applicationId, int sequenceId, int sectionId, string pageId, string title, string getHelp, string controller, string action)
        {
            var getHelpQuery    = new GetHelpWithQuestion();
            var errorMessageKey = string.Format(GetHelpErrorMessageKey, pageId);

            if (string.IsNullOrWhiteSpace(getHelp))
            {
                _sessionService.Set(errorMessageKey, MinLengthErrorMessage);
                var questionKey = string.Format(GetHelpQuestionKey, pageId);
                _sessionService.Set(questionKey, string.Empty);
                return(RedirectToAction(action, controller, new { applicationId, sequenceId, sectionId, pageId }));
            }

            if (getHelp.Length > GetHelpTextMaxLength)
            {
                _sessionService.Set(errorMessageKey, MaxLengthErrorMessage);
                var questionKey = string.Format(GetHelpQuestionKey, pageId);
                _sessionService.Set(questionKey, getHelp);
                return(RedirectToAction(action, controller, new { applicationId, sequenceId, sectionId, pageId }));
            }

            if (applicationId.HasValue && applicationId.Value != Guid.Empty)
            {
                if (sequenceId > 0 && sectionId > 0)
                {
                    var page = await _qnaApiClient.GetPageBySectionNo(applicationId.Value, sequenceId, sectionId, pageId);

                    if (page == null || string.IsNullOrEmpty(page.Title))
                    {
                        getHelpQuery.PageTitle = title;
                    }
                    else
                    {
                        getHelpQuery.PageTitle = page.Title;
                    }

                    var sequenceConfig = _taskListConfiguration.FirstOrDefault(x => x.Id == sequenceId);
                    if (sequenceConfig != null)
                    {
                        getHelpQuery.ApplicationSequence = sequenceConfig.Title;
                    }

                    var currentSection = await _qnaApiClient.GetSectionBySectionNo(applicationId.Value, sequenceId, sectionId);

                    if (currentSection != null)
                    {
                        getHelpQuery.ApplicationSection = currentSection.Title;
                    }
                }
                else
                {
                    getHelpQuery.PageTitle           = title;
                    getHelpQuery.ApplicationSequence = "Not available";
                    getHelpQuery.ApplicationSection  = "Not available";
                }

                var organisationName = await _qnaApiClient.GetAnswerByTag(applicationId.Value, RoatpWorkflowQuestionTags.UkrlpLegalName);

                if (organisationName != null && !string.IsNullOrWhiteSpace(organisationName.Value))
                {
                    getHelpQuery.OrganisationName = organisationName.Value;
                }
                else
                {
                    getHelpQuery.OrganisationName = "Not available";
                }

                var organisationUKPRN = await _qnaApiClient.GetAnswerByTag(applicationId.Value, RoatpWorkflowQuestionTags.UKPRN);

                if (organisationUKPRN != null && !string.IsNullOrWhiteSpace(organisationUKPRN.Value))
                {
                    getHelpQuery.UKPRN = organisationUKPRN.Value;
                }
                else
                {
                    getHelpQuery.UKPRN = "Not available";
                }
            }
            else
            {
                // in preamble so we don't have an application set up yet
                var applicationDetails = _sessionService.Get <ApplicationDetails>(ApplicationDetailsKey);
                getHelpQuery.PageTitle           = title;
                getHelpQuery.ApplicationSequence = "Preamble";
                getHelpQuery.ApplicationSection  = "Preamble";
                var ukprn = applicationDetails?.UKPRN.ToString();
                if (string.IsNullOrWhiteSpace(ukprn))
                {
                    ukprn = "Not available";
                }
                getHelpQuery.UKPRN = ukprn;
                var organisationName = applicationDetails?.UkrlpLookupDetails?.ProviderName;
                if (string.IsNullOrWhiteSpace(organisationName))
                {
                    organisationName = "Not available";
                }
                getHelpQuery.OrganisationName = organisationName;
            }

            getHelpQuery.GetHelpQuery = getHelp;

            var userDetails = await _usersApiClient.GetUserBySignInId(User.GetSignInId());

            getHelpQuery.EmailAddress      = userDetails.Email;
            getHelpQuery.ApplicantFullName = $"{userDetails.GivenNames} {userDetails.FamilyName}";

            await _emailService.SendGetHelpWithQuestionEmail(getHelpQuery);

            var sessionKey = string.Format(GetHelpSubmittedForPageKey, pageId);

            _sessionService.Set(sessionKey, true);
            _sessionService.Set(errorMessageKey, string.Empty);

            return(RedirectToAction(action, controller, new { applicationId, sequenceId, sectionId, pageId }));
        }