コード例 #1
0
        private async Task <IActionResult> StartRoatpApplication(SelectApplicationRouteViewModel model)
        {
            _logger.LogDebug("StartRoatpApplication invoked");

            var applicationDetails = _sessionService.Get <ApplicationDetails>(ApplicationDetailsKey);

            applicationDetails.ApplicationRoute = new ApplicationRoute {
                Id = model.ApplicationRouteId
            };

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

            applicationDetails.CreatedBy = user.Id;

            var createOrganisationRequest = Mapper.Map <CreateOrganisationRequest>(applicationDetails);

            await _organisationApiClient.Create(createOrganisationRequest, user.Id);

            _sessionService.Set(ApplicationDetailsKey, applicationDetails);

            if (!user.IsApproved)
            {
                await _usersApiClient.ApproveUser(user.Id);
            }

            _logger.LogDebug("StartRoatpApplication completed");

            return(RedirectToAction("Applications", "RoatpApplication", new { applicationType = ApplicationTypes.RegisterTrainingProviders }));
        }
        public async Task <IActionResult> PostSignIn()
        {
            var user = await _usersApiClient.GetUserBySignInId(User.GetSignInId());

            if (user is null)
            {
                return(RedirectToAction("NotSetUp"));
            }
            else if (user.ApplyOrganisationId is null)
            {
                return(RedirectToAction("EnterApplicationUkprn", "RoatpApplicationPreamble"));
            }

            var selectedApplicationType = ApplicationTypes.RegisterTrainingProviders;

            return(RedirectToAction("Applications", "RoatpApplication", new { applicationType = selectedApplicationType }));
        }
コード例 #3
0
        public async Task <IActionResult> PostSignIn()
        {
            var signInId = User.GetSignInId();
            var user     = await _usersApiClient.GetUserBySignInId(signInId);

            if (user is null)
            {
                return(RedirectToAction("NotSetUp"));
            }
            else if (user.ApplyOrganisationId is null)
            {
                return(RedirectToAction("EnterApplicationUkprn", "RoatpApplicationPreamble"));
            }

            var reapplicationAllowed =
                await _reapplicationCheckService.ReapplicationAllowed(signInId, user.ApplyOrganisationId);

            if (reapplicationAllowed)
            {
                var ukprn = await _reapplicationCheckService.ReapplicationUkprnForUser(User.GetSignInId());

                if (string.IsNullOrEmpty(ukprn))
                {
                    return(RedirectToAction("EnterApplicationUkprn", "RoatpApplicationPreamble"));
                }
            }

            var reapplicationRequestedAndPending =
                await _reapplicationCheckService.ReapplicationRequestedAndPending(signInId, user.ApplyOrganisationId);

            if (reapplicationRequestedAndPending)
            {
                var applicationId = await _reapplicationCheckService.ReapplicationApplicationIdForUser(signInId);

                if (applicationId != null && applicationId != Guid.Empty)
                {
                    return(RedirectToAction("RequestNewInvitationRefresh", "RoatpAppeals", new { applicationId }));
                }
            }

            return(RedirectToAction("Applications", "RoatpApplication", new { applicationType = ApplicationTypes.RegisterTrainingProviders }));
        }
        public async Task <bool> AssociateOrgFromClaimWithUser()
        {
            //Check if where comming from assessor as a new user associated with registered EPAO
            //if so try associating the registered org with existing user
            try
            {
                var orgName = await GetClaim(
                    "http://schemas.portal.com/orgname");

                if (!string.IsNullOrEmpty(orgName))
                {
                    var signInId = await GetClaim("sub");

                    var contact = await _usersApiClient.GetUserBySignInId(signInId);

                    if (contact != null)
                    {
                        var orgFromName = await _apiClient.GetOrganisationByName(orgName);

                        if (orgFromName != null)
                        {
                            await _usersApiClient.AssociateOrganisationWithUser(contact.Id, orgFromName.Id);
                        }
                        else
                        {
                            return(false);
                        }

                        return(true);
                    }
                }
            }
            catch (ArgumentException)
            {
                _logger.LogInformation("Faild to retrieve organisation from Assessor so just carry on for now.");
                //Ignore and just fall through
            }

            return(false);
        }
コード例 #5
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 }));
        }
コード例 #6
0
        public async Task <IActionResult> Index(Guid?applicationId, int sequenceId, int sectionId, string pageId, string title, string getHelp, string controller, string action)
        {
            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 }));
            }

            var sequenceConfig = _taskListConfiguration.FirstOrDefault(x => x.Id == sequenceId);
            var getHelpQuery   = new GetHelpWithQuestion
            {
                ApplicationSequence = sequenceConfig?.Title ?? $"Not available (Sequence {sequenceId})",
                ApplicationSection  = $"Not available (Section {sectionId}))",
                PageTitle           = title ?? action,
                OrganisationName    = "Not available",
                UKPRN         = "Not available",
                CompanyNumber = "Not available",
                CharityNumber = "Not available",
            };

            if (applicationId.HasValue && applicationId.Value != Guid.Empty)
            {
                try
                {
                    var qnaApplicationData = await _qnaApiClient.GetApplicationData(applicationId.Value);

                    var organisationName = qnaApplicationData.GetValue(RoatpWorkflowQuestionTags.UkrlpLegalName)?.Value <string>();
                    if (!string.IsNullOrWhiteSpace(organisationName))
                    {
                        getHelpQuery.OrganisationName = organisationName;
                    }

                    var organisationUKPRN = qnaApplicationData.GetValue(RoatpWorkflowQuestionTags.UKPRN)?.Value <string>();
                    if (!string.IsNullOrWhiteSpace(organisationUKPRN))
                    {
                        getHelpQuery.UKPRN = organisationUKPRN;
                    }

                    var organisationCompanyNumber = qnaApplicationData.GetValue(RoatpWorkflowQuestionTags.UKRLPVerificationCompanyNumber)?.Value <string>();
                    if (!string.IsNullOrWhiteSpace(organisationCompanyNumber))
                    {
                        getHelpQuery.CompanyNumber = organisationCompanyNumber;
                    }

                    var organisationCharityNumber = qnaApplicationData.GetValue(RoatpWorkflowQuestionTags.UKRLPVerificationCharityRegNumber)?.Value <string>();
                    if (!string.IsNullOrWhiteSpace(organisationCharityNumber))
                    {
                        getHelpQuery.CharityNumber = organisationCharityNumber;
                    }

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

                    if (!string.IsNullOrEmpty(currentSection?.Title))
                    {
                        getHelpQuery.ApplicationSection = currentSection.Title;
                    }

                    var currentPage = currentSection?.QnAData.Pages.FirstOrDefault(pg => pg.PageId == pageId);
                    if (!string.IsNullOrEmpty(currentPage?.Title))
                    {
                        getHelpQuery.PageTitle = currentPage.Title;
                    }
                }
                catch (ApplyService.Infrastructure.Exceptions.ApiClientException apiEx)
                {
                    // Safe to ignore any QnA issues. We just want to send help with as much info as possible.
                    _logger.LogError(apiEx, $"Unable to retrieve QNA details for application : {applicationId.Value}");
                }
                catch (NullReferenceException nullRefEx)
                {
                    // Safe to ignore any QnA issues. We just want to send help with as much info as possible.
                    _logger.LogError(nullRefEx, $"QNA details were not found for application: {applicationId.Value}");
                }
            }
            else
            {
                // in preamble so we don't have an application set up yet
                getHelpQuery.ApplicationSequence = "Preamble";
                getHelpQuery.ApplicationSection  = "Preamble";

                var applicationDetails = _sessionService.Get <ApplicationDetails>(ApplicationDetailsKey);

                if (applicationDetails != null)
                {
                    getHelpQuery.UKPRN = applicationDetails.UKPRN.ToString();

                    var organisationName = applicationDetails.UkrlpLookupDetails?.ProviderName;
                    if (!string.IsNullOrWhiteSpace(organisationName))
                    {
                        getHelpQuery.OrganisationName = organisationName;
                    }

                    var organisationCompanyNumber = applicationDetails.UkrlpLookupDetails?.VerificationDetails?.FirstOrDefault(x => x.VerificationAuthority == Domain.Ukrlp.VerificationAuthorities.CompaniesHouseAuthority)?.VerificationId;
                    if (!string.IsNullOrWhiteSpace(organisationCompanyNumber))
                    {
                        getHelpQuery.CompanyNumber = organisationCompanyNumber;
                    }

                    var organisationCharityNumber = applicationDetails.UkrlpLookupDetails?.VerificationDetails?.FirstOrDefault(x => x.VerificationAuthority == Domain.Ukrlp.VerificationAuthorities.CharityCommissionAuthority)?.VerificationId;
                    if (!string.IsNullOrWhiteSpace(organisationCharityNumber))
                    {
                        getHelpQuery.CharityNumber = organisationCharityNumber;
                    }
                }
            }

            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 }));
        }