예제 #1
0
        private async Task <string> ApplicationStandardStatus(ApplicationResponse application, int standardCode)
        {
            var validApplicationStatuses         = new string[] { ApplicationStatus.InProgress };
            var validApplicationSequenceStatuses = new string[] { ApplicationSequenceStatus.Draft };

            var applicationData = await _qnaApiClient.GetApplicationData(application.ApplicationId);

            var org = await _orgApiClient.GetEpaOrganisationById(applicationData.OrganisationReferenceId);

            var standards = await _orgApiClient.GetOrganisationStandardsByOrganisation(org?.OrganisationId);

            var standard = standards?.SingleOrDefault(x => x.StandardCode == standardCode);

            // does the org or the application not have the standard &&
            if (standard == null && application?.ApplyData != null)
            {
                var userId = await GetUserId();

                var applications = await _apiClient.GetStandardApplications(userId);

                foreach (var app in applications)
                {
                    if (app.OrganisationId == org?.Id && app.ApplyData.Apply.StandardCode == standardCode)
                    {
                        if (validApplicationStatuses.Contains(application.ApplicationStatus))
                        {
                            var sequence = application.ApplyData.Sequences?.FirstOrDefault(seq => seq.IsActive && seq.SequenceNo == ApplyConst.STANDARD_SEQUENCE_NO);

                            if (sequence != null && validApplicationSequenceStatuses.Contains(sequence.Status))
                            {
                                return(sequence.Status);
                            }
                        }
                    }
                }
            }
            else if ((standard.EffectiveTo == null || standard.EffectiveTo > DateTime.UtcNow) && org.Status == OrganisationStatus.Live)
            {
                return(ApplicationStatus.Approved);
            }

            return(string.Empty);
        }
예제 #2
0
        public async Task <ActionResult <ApiValidationResult> > ValidateWithdrawalDate(Guid id, string q)
        {
            try
            {
                var application = await _mediator.Send(new GetApplicationRequest(id));

                var appData = await _qnaApiClient.GetApplicationData(application.ApplicationId);

                if ((appData.PipelinesCount ?? 0) != 0)
                {
                    var dateComponents = q.Split(",");
                    var enteredDate    = new DateTime(int.Parse(dateComponents[2]), int.Parse(dateComponents[1]), int.Parse(dateComponents[0]));
                    if (enteredDate < appData.EarliestDateOfWithdrawal.Date)
                    {
                        return new ApiValidationResult
                               {
                                   IsValid       = false,
                                   ErrorMessages = new List <KeyValuePair <string, string> >()
                                   {
                                       new KeyValuePair <string, string>("", $"Date must not be before {appData.EarliestDateOfWithdrawal.Date:d MMM yyyy}")
                                   }
                               }
                    }
                    ;
                }

                return(new ApiValidationResult {
                    IsValid = true
                });
            }
            catch (Exception ex)
            {
                _logger.LogError($"Exception during withdrawal date validation for {q} : { ex.Message}");

                return(new ApiValidationResult
                {
                    IsValid = false,
                    ErrorMessages = new List <KeyValuePair <string, string> >()
                });
            }
        }
        public async Task <IActionResult> StartPage(Guid applicationId)
        {
            var qnaApplicationData = await _qnaApiClient.GetApplicationData(applicationId);

            var companyNumber                   = qnaApplicationData.GetValue(RoatpWorkflowQuestionTags.UKRLPVerificationCompanyNumber)?.Value <string>();
            var ukprn                           = qnaApplicationData.GetValue(RoatpWorkflowQuestionTags.UKPRN)?.Value <string>();
            var verificationCompanyAnswer       = qnaApplicationData.GetValue(RoatpWorkflowQuestionTags.UkrlpVerificationCompany)?.Value <string>();
            var companiesHouseManualEntryAnswer = qnaApplicationData.GetValue(RoatpWorkflowQuestionTags.ManualEntryRequiredCompaniesHouse)?.Value <string>();

            if (verificationCompanyAnswer == "TRUE" &&
                companiesHouseManualEntryAnswer != "TRUE")
            {
                return(RedirectToAction("ConfirmDirectorsPscs", new { applicationId, ukprn, companyNumber }));
            }

            var verificationCharityAnswer          = qnaApplicationData.GetValue(RoatpWorkflowQuestionTags.UkrlpVerificationCharity)?.Value <string>();
            var charityCommissionManualEntryAnswer = qnaApplicationData.GetValue(RoatpWorkflowQuestionTags.ManualEntryRequiredCharityCommission)?.Value <string>();

            if (verificationCharityAnswer == "TRUE" &&
                charityCommissionManualEntryAnswer != "TRUE")
            {
                return(RedirectToAction("ConfirmTrustees", new { applicationId }));
            }

            var verificationPartnership = qnaApplicationData.GetValue(RoatpWorkflowQuestionTags.UkrlpVerificationSoleTraderPartnership)?.Value <string>();

            if (verificationPartnership == "TRUE")
            {
                return(RedirectToAction("SoleTraderOrPartnership", new { applicationId }));
            }

            var peopleData = qnaApplicationData.GetValue(RoatpWorkflowQuestionTags.AddPeopleInControl)?.Value <string>();

            if (peopleData != null)
            {
                return(RedirectToAction("ConfirmPeopleInControl", new { applicationId }));
            }

            return(RedirectToAction("AddPeopleInControl", new { applicationId }));
        }
        private async Task <List <NotRequiredOverrideConfiguration> > CalculateNotRequiredOverridesAsync(Guid applicationId)
        {
            List <NotRequiredOverrideConfiguration> configuration = null;

            var applicationData = (await _qnaApiClient.GetApplicationData(applicationId)) as JObject;

            if (applicationData != null)
            {
                configuration = new List <NotRequiredOverrideConfiguration>(_configuration);

                foreach (var overrideConfig in configuration)
                {
                    foreach (var condition in overrideConfig.Conditions)
                    {
                        var applicationDataValue = applicationData[condition.ConditionalCheckField];
                        condition.Value = applicationDataValue != null?applicationDataValue.Value <string>() : string.Empty;
                    }
                }
            }

            return(configuration);
        }
        public async Task <OrganisationVerificationStatus> GetOrganisationVerificationStatus(Guid applicationId)
        {
            try
            {
                var qnaApplicationData = await _qnaApiClient.GetApplicationData(applicationId);

                return(new OrganisationVerificationStatus
                {
                    VerifiedCompaniesHouse = VerifiedCompaniesHouse(qnaApplicationData),
                    VerifiedCharityCommission = VerifiedCharityCommission(qnaApplicationData),
                    CompaniesHouseManualEntry = CompaniesHouseManualEntry(qnaApplicationData),
                    CharityCommissionManualEntry = CharityCommissionManualEntry(qnaApplicationData),
                    CompaniesHouseDataConfirmed = CompaniesHouseDataConfirmed(qnaApplicationData),
                    CharityCommissionDataConfirmed = CharityCommissionDataConfirmed(qnaApplicationData),
                    WhosInControlConfirmed = WhosInControlConfirmed(qnaApplicationData),
                    WhosInControlStarted = WhosInControlStarted(qnaApplicationData)
                });
            }
            catch (NullReferenceException)
            {
                return(new OrganisationVerificationStatus());
            }
        }
        public async Task <IActionResult> ConfirmStandard(StandardVersionViewModel model, Guid id, string standardReference, string version)
        {
            var application = await _applicationApiClient.GetApplication(id);

            if (!CanUpdateApplicationAsync(application))
            {
                return(RedirectToAction("Applications", "Application"));
            }

            var org = await _orgApiClient.GetEpaOrganisation(application.OrganisationId.ToString());

            var standardVersions = (await _orgApiClient.GetAppliedStandardVersionsForEPAO(org?.OrganisationId, standardReference))
                                   .OrderBy(s => s.Version);

            bool anyExistingVersions = standardVersions.Any(x => x.ApprovedStatus == ApprovedStatus.Approved || x.ApplicationStatus == ApplicationStatus.Submitted);

            AppliedStandardVersion selectedStandard = null;
            string        applicationStatus         = null;
            List <string> versions = null;

            if (string.IsNullOrWhiteSpace(version))
            {
                selectedStandard = standardVersions.LastOrDefault();
                versions         = model.SelectedVersions ?? new List <string> {
                    selectedStandard.Version
                };
                if (model.SelectedVersions != null)
                {
                    applicationStatus = await ApplicationStandardStatus(application, standardReference, model.SelectedVersions);
                }
            }
            else
            {
                selectedStandard = standardVersions.FirstOrDefault(x => x.Version == version);
                versions         = new List <string> {
                    selectedStandard.Version
                };
            }

            // check that the confirm checkbox has been selected
            if (!model.IsConfirmed)
            {
                ModelState.AddModelError(nameof(model.IsConfirmed), "Confirm you have read the assessment plan");
                TempData["ShowConfirmedError"] = true;
            }

            // check that a version has been selected
            if (string.IsNullOrWhiteSpace(version) &&
                standardVersions.Count() > 1 &&
                (model.SelectedVersions == null || !model.SelectedVersions.Any()))
            {
                ModelState.AddModelError(nameof(model.SelectedVersions), "You must select at least one version");
                TempData["ShowVersionError"] = true;
            }

            if (!ModelState.IsValid || !string.IsNullOrWhiteSpace(applicationStatus))
            {
                model.Results = string.IsNullOrWhiteSpace(version) ? standardVersions.Select(s => (StandardVersion)s).ToList() :
                                new List <StandardVersion>()
                {
                    selectedStandard
                };
                model.SelectedStandard  = (StandardVersion)selectedStandard;
                model.ApplicationStatus = applicationStatus;
                return(View("~/Views/Application/Standard/ConfirmStandard.cshtml", model));
            }
            else if (anyExistingVersions)
            {
                await _applicationApiClient.UpdateStandardData(id, selectedStandard.LarsCode, selectedStandard.IFateReferenceNumber, selectedStandard.Title, versions, StandardApplicationTypes.Version);

                // update QnA application data for the Application Type
                var applicationData = await _qnaApiClient.GetApplicationData(application.ApplicationId);

                applicationData.ApplicationType = StandardApplicationTypes.Version;
                await _qnaApiClient.UpdateApplicationData(application.ApplicationId, applicationData);
            }
            else
            {
                await _applicationApiClient.UpdateStandardData(id, selectedStandard.LarsCode, selectedStandard.IFateReferenceNumber, selectedStandard.Title, versions, StandardApplicationTypes.Full);
            }

            return(RedirectToAction("SequenceSignPost", "Application", new { Id = id }));
        }
예제 #7
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 }));
        }