private async Task LookupCharityCommissionDetails(ApplyGatewayDetails applyGatewayDetails, string charityNumberFromUkrlp)
        {
            if (!int.TryParse(charityNumberFromUkrlp, out var charityNumber))
            {
                var message =
                    $"Charity registration number cannot be parsed into a number, skipping getting details from charity commission for '{ charityNumberFromUkrlp}'";

                _logger.LogInformation(message);
                return;
            }

            try
            {
                var charityDetails = await _outerApiClient.GetCharityDetails(charityNumber);

                applyGatewayDetails.CharityCommissionDetails = Mapper.Map <CharityCommissionSummary>(charityDetails);
            }
            catch (Exception ex)
            {
                var message = $"Unable to retrieve Charity Commission details for charity number {charityNumber} based on charity number from uklrp: {charityNumberFromUkrlp}";
                _logger.LogError(ex, message);
                throw new ServiceUnavailableException(message);
            }
        }
Пример #2
0
        public async Task <IActionResult> VerifyOrganisationDetails()
        {
            var applicationDetails = _sessionService.Get <ApplicationDetails>(ApplicationDetailsKey);
            var providerDetails    = applicationDetails.UkrlpLookupDetails;

            var existingApplicationStatuses = await _applicationApiClient.GetExistingApplicationStatus(providerDetails.UKPRN);

            if (existingApplicationStatuses.Any(x => x.Status == ApplicationStatus.InProgress))
            {
                return(RedirectToAction("ApplicationInProgress", "RoatpShutterPages", new ExistingApplicationViewModel {
                    UKPRN = providerDetails.UKPRN
                }));
            }
            else if (existingApplicationStatuses.Any(x => x.Status == ApplicationStatus.Submitted || x.Status == ApplicationStatus.GatewayAssessed))
            {
                return(RedirectToAction("ApplicationPreviouslySubmitted", "RoatpShutterPages", new ExistingApplicationViewModel {
                    UKPRN = providerDetails.UKPRN
                }));
            }

            CompaniesHouseSummary companyDetails = null;
            Charity charityDetails = null;

            if (providerDetails.VerifiedByCompaniesHouse)
            {
                var companiesHouseVerification = providerDetails.VerificationDetails.FirstOrDefault(x =>
                                                                                                    x.VerificationAuthority == VerificationAuthorities.CompaniesHouseAuthority);

                companyDetails = await _companiesHouseApiClient.GetCompanyDetails(companiesHouseVerification.VerificationId);

                if ((companyDetails.Directors == null || companyDetails.Directors.Count == 0) &&
                    (companyDetails.PersonsWithSignificantControl == null ||
                     companyDetails.PersonsWithSignificantControl.Count == 0))
                {
                    companyDetails.ManualEntryRequired = true;
                }

                if (companyDetails.Status == CompaniesHouseSummary.ServiceUnavailable)
                {
                    return(RedirectToAction("CompaniesHouseNotAvailable", "RoatpShutterPages"));
                }
                else if (companyDetails.Status == CompaniesHouseSummary.CompanyStatusNotFound)
                {
                    return(RedirectToAction("CompanyNotFound", "RoatpShutterPages"));
                }
                else if (!CompaniesHouseValidator.CompaniesHouseStatusValid(providerDetails.UKPRN, companyDetails.Status, _logger))
                {
                    return(RedirectToAction("CompanyNotFound", "RoatpShutterPages"));
                }

                applicationDetails.CompanySummary = companyDetails;
            }

            if (applicationDetails.UkrlpLookupDetails.VerifiedbyCharityCommission)
            {
                var charityCommissionVerification = providerDetails.VerificationDetails.FirstOrDefault(x =>
                                                                                                       x.VerificationAuthority == VerificationAuthorities.CharityCommissionAuthority);

                string verificationId = charityCommissionVerification.VerificationId;
                if (verificationId.Contains("-"))
                {
                    verificationId = verificationId.Substring(0, verificationId.IndexOf("-"));
                }

                if (IsEnglandAndWalesCharityCommissionNumber(verificationId))
                {
                    bool isValidCharityNumber = int.TryParse(verificationId, out var charityNumber);
                    if (!isValidCharityNumber)
                    {
                        return(RedirectToAction("CharityNotFound", "RoatpShutterPages"));
                    }

                    try
                    {
                        charityDetails = await _outerApiClient.GetCharityDetails(charityNumber);
                    }
                    catch (Exception ex)
                    {
                        _logger.LogError(ex, "Error fetching charity details for charity number `{charityNumber}`", charityNumber);
                        return(RedirectToAction("CharityCommissionNotAvailable", "RoatpShutterPages"));
                    }

                    if (!charityDetails.IsActivelyTrading)
                    {
                        return(RedirectToAction("CharityNotFound", "RoatpShutterPages"));
                    }

                    applicationDetails.CharitySummary = Mapper.Map <CharityCommissionSummary>(charityDetails);
                }
                else
                {
                    applicationDetails.CharitySummary = new CharityCommissionSummary
                    {
                        TrusteeManualEntryRequired = true
                    };
                }
            }

            var roatpRegisterStatus = await _roatpApiClient.GetOrganisationRegisterStatus(applicationDetails.UKPRN);

            applicationDetails.RoatpRegisterStatus = roatpRegisterStatus;

            _sessionService.Set(ApplicationDetailsKey, applicationDetails);

            if (ProviderEligibleToChangeRoute(roatpRegisterStatus))
            {
                return(RedirectToAction("ProviderAlreadyOnRegister"));
            }

            return(RedirectToAction("SelectApplicationRoute"));
        }
Пример #3
0
        public async Task <RefreshTrusteesResult> RefreshTrustees(Guid applicationId, Guid userId)
        {
            var organisation = await _organisationApiClient.GetByApplicationId(applicationId);

            var ukprn         = organisation?.OrganisationUkprn?.ToString();
            var charityNumber = organisation?.OrganisationDetails?.CharityNumber;

            if (ukprn == null || charityNumber == null || !int.TryParse(charityNumber, out var charityNumberValue))
            {
                _logger.LogInformation($"RefreshTrusteesService: Refresh failure for applicationId {applicationId}, ukprn: [{ukprn}], Charity number: [{charityNumber}]");

                return(new RefreshTrusteesResult {
                    CharityDetailsNotFound = true, CharityNumber = charityNumber
                });
            }

            var application = await _applicationApiClient.GetApplication(applicationId);

            if (application.ApplicationStatus != ApplicationStatus.InProgress)
            {
                _logger.LogInformation($"RefreshTrusteesService: Refresh failure for applicationId {applicationId} as status '{ApplicationStatus.InProgress}' expected.");
                return(new RefreshTrusteesResult {
                    CharityDetailsNotFound = true, CharityNumber = charityNumber
                });
            }

            Charity charityDetails;

            try
            {
                _logger.LogInformation($"RefreshTrusteesService:  retrieving charity details for applicationId {applicationId}  for charity registration number '{charityNumberValue}'");
                charityDetails = await _outerApiClient.GetCharityDetails(charityNumberValue);
            }
            catch (Exception ex)
            {
                var message =
                    $"RefreshTrusteesService: Exception for Application {applicationId}, failed to get charity details for charity number: [{charityNumberValue}]";
                _logger.LogError(ex, message);
                throw new InvalidOperationException(message, ex);
            }

            if (charityDetails == null || !charityDetails.IsActivelyTrading || charityDetails.Trustees == null || !charityDetails.Trustees.Any())
            {
                _logger.LogInformation($"RefreshTrusteesService:  Failure for applicationId {applicationId}  to retrieve trustee details from charity '{charityNumberValue}'");
                return(new RefreshTrusteesResult {
                    CharityDetailsNotFound = true, CharityNumber = charityNumber
                });
            }

            _logger.LogInformation($"RefreshTrusteesService: updating organisation trustees applicationId {applicationId}");

            try
            {
                var success = await _organisationApiClient.UpdateTrustees(ukprn, charityDetails.Trustees?.ToList(), userId);

                if (!success)
                {
                    throw new InvalidOperationException($"RefreshTrusteesService for Application {applicationId} update trustees failed");
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException($"RefreshTrusteesService for Application {applicationId} update trustees failed: [{ex.Message}]");
            }

            var applicationDetails = new Domain.Roatp.ApplicationDetails {
                CharitySummary = Mapper.Map <CharityCommissionSummary>(charityDetails)
            };
            var trusteesAnswers = RoatpPreambleQuestionBuilder.CreateCharityCommissionWhosInControlQuestions(applicationDetails);

            _logger.LogInformation($"RefreshTrusteesService: resetting page answers for charities for page 80, 86 and section 3.4, applicationId {applicationId}");
            try
            {
                var resetSection1_3_80 = _qnaApiClient.ResetPageAnswersBySequenceAndSectionNumber(applicationId, RoatpWorkflowSequenceIds.YourOrganisation, RoatpWorkflowSectionIds.YourOrganisation.WhosInControl, RoatpWorkflowPageIds.WhosInControl.CharityCommissionTrustees);
                var resetSection1_3_86 = _qnaApiClient.ResetPageAnswersBySequenceAndSectionNumber(applicationId, RoatpWorkflowSequenceIds.YourOrganisation, RoatpWorkflowSectionIds.YourOrganisation.WhosInControl, RoatpWorkflowPageIds.WhosInControl.CharityCommissionTrusteesDob);
                var resetSection3_4    = _qnaApiClient.ResetPageAnswersBySection(applicationId, RoatpWorkflowSequenceIds.CriminalComplianceChecks, RoatpWorkflowSectionIds.CriminalComplianceChecks.CheckOnWhosInControl);
                await Task.WhenAll(resetSection1_3_80, resetSection1_3_86, resetSection3_4);

                _logger.LogInformation($"RefreshTrusteesService: updating page answers for charities, applicationId {applicationId}");
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException($"RefreshTrusteesService for Application {applicationId} reset qna page answers failed: [{ex.Message}]");
            }

            try
            {
                var response = await _qnaApiClient.UpdatePageAnswers(applicationId,
                                                                     RoatpWorkflowSequenceIds.YourOrganisation, RoatpWorkflowSectionIds.YourOrganisation.WhosInControl,
                                                                     RoatpWorkflowPageIds.WhosInControl.CharityCommissionTrustees, trusteesAnswers.ToList <Answer>());

                if (!response.ValidationPassed)
                {
                    throw new InvalidOperationException($"RefreshTrusteesService for Application {applicationId} update qna page answers failed");
                }
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException($"RefreshTrusteesService for Application {applicationId} update qna page answers failed: [{ex.Message}]");
            }

            return(new RefreshTrusteesResult
            {
                CharityNumber = charityNumber,
                CharityDetailsNotFound = false
            });
        }