public void Preamble_questions_contains_web_site()
        {
            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.UkrlpWebsite);

            question.Should().NotBeNull();
            question.Value.Should().Be(_applicationDetails.UkrlpLookupDetails.PrimaryContactDetails.ContactWebsiteAddress);
        }
        public void Preamble_questions_contains_UKPRN()
        {
            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.UKPRN);

            question.Should().NotBeNull();
            question.Value.Should().Be(_applicationDetails.UKPRN.ToString());
        }
        public void Preamble_questions_contains_legal_name()
        {
            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.UkrlpLegalName);

            question.Should().NotBeNull();
            question.Value.Should().Be(_applicationDetails.UkrlpLookupDetails.ProviderName);
        }
        public void Preamble_questions_contains_legal_address_postcode()
        {
            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.UkrlpLegalAddressPostcode);

            question.Should().NotBeNull();
            question.Value.Should().Be(_applicationDetails.UkrlpLookupDetails.PrimaryContactDetails.ContactAddress.PostCode);
        }
        public void Preamble_questions_contains_conditions_of_acceptance_stage_1_application()
        {
            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.COAStage1Application);

            question.Should().NotBeNull();
            question.Value.Should().Be("TRUE");
        }
        public void Preamble_questions_contains_no_web_site_flag(string websiteUrl, string expectedValue)
        {
            _applicationDetails.UkrlpLookupDetails.PrimaryContactDetails.ContactWebsiteAddress = websiteUrl;
            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.UKrlpNoWebsite);

            question.Should().NotBeNull();
            question.Value.Should().Be(expectedValue);
        }
        public void Preamble_questions_contains_companies_house_manual_entry_required_flag(bool manualEntryFlag, string expectedValue)
        {
            _applicationDetails.CompanySummary.ManualEntryRequired = manualEntryFlag;

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.CompaniesHouseManualEntryRequired);

            question.Should().NotBeNull();
            question.Value.Should().Be(expectedValue);
        }
        public void Preamble_questions_contains_roatp_current_status()
        {
            _applicationDetails.RoatpRegisterStatus = new OrganisationRegisterStatus {
                UkprnOnRegister = true, StatusId = OrganisationStatus.Active
            };

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.RoatpCurrentStatus);

            question.Should().NotBeNull();
            question.Value.Should().Be(OrganisationStatus.Active.ToString());
        }
        public void Preamble_questions_contains_roatp_provider_route()
        {
            _applicationDetails.RoatpRegisterStatus = new OrganisationRegisterStatus {
                UkprnOnRegister = true, ProviderTypeId = ApplicationRoute.MainProviderApplicationRoute
            };

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.RoatpProviderRoute);

            question.Should().NotBeNull();
            question.Value.Should().Be(ApplicationRoute.MainProviderApplicationRoute.ToString());
        }
        public void Preamble_questions_contains_on_roatp_flag()
        {
            _applicationDetails.RoatpRegisterStatus = new OrganisationRegisterStatus {
                UkprnOnRegister = true
            };

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.OnRoatp);

            question.Should().NotBeNull();
            question.Value.Should().Be("TRUE");
        }
        public void Preamble_questions_contains_apply_supporting_provider_route()
        {
            _applicationDetails.ApplicationRoute = new ApplicationRoute {
                Id = ApplicationRoute.SupportingProviderApplicationRoute
            };
            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(
                x => x.QuestionId == RoatpPreambleQuestionIdConstants.ApplyProviderRoute);

            question.Should().NotBeNull();
            question.Value.Should().Be("3");
        }
        public void Preamble_questions_contains_roatp_removed_reason()
        {
            _applicationDetails.RoatpRegisterStatus = new OrganisationRegisterStatus
            {
                UkprnOnRegister = true, StatusId = OrganisationStatus.Removed, RemovedReasonId = RemovedReason.ChangeOfTradingStatus
            };

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.RoatpRemovedReason);

            question.Should().NotBeNull();
            question.Value.Should().Be(RemovedReason.ChangeOfTradingStatus.ToString());
        }
        public void Preamble_questions_contains_companies_house_incorporation_date()
        {
            _applicationDetails.CompanySummary = new CompaniesHouseSummary
            {
                IncorporationDate = new DateTime(2017, 03, 08)
            };

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.CompaniesHouseIncorporationDate);

            question.Should().NotBeNull();
            question.Value.Should().Be(_applicationDetails.CompanySummary.IncorporationDate.Value.ToString());
        }
        public void Preamble_questions_contains_companies_house_company_type()
        {
            _applicationDetails.CompanySummary = new CompaniesHouseSummary
            {
                CompanyType = "ltd"
            };

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.CompaniesHouseCompanyType);

            question.Should().NotBeNull();
            question.Value.Should().Be(_applicationDetails.CompanySummary.CompanyTypeDescription);
        }
        public void Preamble_questions_contains_charity_commission_registration_date()
        {
            _applicationDetails.CharitySummary = new CharityCommissionSummary
            {
                RegistrationDate = new DateTime(2015, 03, 17)
            };

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.CharityCommissionRegistrationDate);

            question.Should().NotBeNull();
            question.Value.Should().Be(_applicationDetails.CharitySummary.RegistrationDate.Value.ToString());
        }
        public void Preamble_questions_contains_charity_commission_charity_name()
        {
            _applicationDetails.CharitySummary = new CharityCommissionSummary
            {
                Name = "Charity name"
            };

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.CharityCommissionCharityName);

            question.Should().NotBeNull();
            question.Value.Should().Be(_applicationDetails.CharitySummary.Name);
        }
        public void Preamble_questions_contains_charity_commission_trustee_manual_entry_flag(bool manualEntryRequired, string expectedValue)
        {
            _applicationDetails.CharitySummary = new CharityCommissionSummary
            {
                TrusteeManualEntryRequired = manualEntryRequired
            };

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.CharityCommissionTrusteeManualEntry);

            question.Should().NotBeNull();
            question.Value.Should().Be(expectedValue);
        }
        public void Preamble_questions_contains_roatp_status_date()
        {
            _applicationDetails.RoatpRegisterStatus = new OrganisationRegisterStatus
            {
                UkprnOnRegister = true, StatusId = OrganisationStatus.Active, StatusDate = new DateTime(2014, 02, 02)
            };

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.RoatpStatusDate);

            question.Should().NotBeNull();
            question.Value.Should().Be(_applicationDetails.RoatpRegisterStatus.StatusDate.Value.ToString());
        }
        public void Preamble_questions_contains_companies_house_company_status()
        {
            _applicationDetails.CompanySummary = new CompaniesHouseSummary
            {
                Status = CompaniesHouseSummary.CompanyStatusActive
            };

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.CompaniesHouseCompanyStatus);

            question.Should().NotBeNull();
            question.Value.Should().Be(_applicationDetails.CompanySummary.Status);
        }
        public void Preamble_questions_contains_roatp_RouteAndOnRoatp_status(bool onRegister, int route, string expectedValue)
        {
            _applicationDetails.RoatpRegisterStatus = new OrganisationRegisterStatus {
                UkprnOnRegister = onRegister
            };
            _applicationDetails.ApplicationRoute = new ApplicationRoute {
                Id = route
            };

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();
            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.RouteAndOnRoatp);

            question.Should().NotBeNull();
            question.Value.Should().Be(expectedValue);
        }
        public void Preamble_questions_contains_charity_commission_verification_flag()
        {
            _applicationDetails.UkrlpLookupDetails.VerificationDetails = new List <VerificationDetails>
            {
                new VerificationDetails {
                    VerificationAuthority = VerificationAuthorities.CharityCommissionAuthority, VerificationId = "1234567"
                }
            };

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.UkrlpVerificationCharity);

            question.Should().NotBeNull();
            question.Value.Should().Be("TRUE");
        }
        public void Preamble_questions_contains_UKRLP_verification_company_number()
        {
            _applicationDetails.UkrlpLookupDetails.VerificationDetails = new List <VerificationDetails>
            {
                new VerificationDetails {
                    VerificationAuthority = VerificationAuthorities.CompaniesHouseAuthority, VerificationId = "01234567"
                }
            };

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.UkrlpVerificationCompanyNumber);

            question.Should().NotBeNull();
            question.Value.Should().Be(_applicationDetails.UkrlpLookupDetails.VerificationDetails.FirstOrDefault(x => x.VerificationAuthority == VerificationAuthorities.CompaniesHouseAuthority).VerificationId);
        }
        public void Preamble_questions_contains_UKRLP_verification_sole_trader_partnership()
        {
            _applicationDetails.UkrlpLookupDetails.VerificationDetails = new List <VerificationDetails>
            {
                new VerificationDetails
                {
                    VerificationAuthority = VerificationAuthorities.SoleTraderPartnershipAuthority,
                    VerificationId        = "Y"
                }
            };

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.UkrlpVerificationSoleTraderPartnership);

            question.Should().NotBeNull();
            question.Value.Should().Be("TRUE");
        }
        public void Preamble_questions_contains_UKRLP_primary_verification_source()
        {
            _applicationDetails.UkrlpLookupDetails.VerificationDetails = new List <VerificationDetails>
            {
                new VerificationDetails {
                    VerificationAuthority = VerificationAuthorities.CharityCommissionAuthority, VerificationId = "1234567"
                },
                new VerificationDetails {
                    VerificationAuthority = VerificationAuthorities.CompaniesHouseAuthority, VerificationId = "01234567", PrimaryVerificationSource = true
                }
            };

            var questions = RoatpPreambleQuestionBuilder.CreatePreambleQuestions(_applicationDetails);

            questions.Should().NotBeNull();

            var question = questions.FirstOrDefault(x => x.QuestionId == RoatpPreambleQuestionIdConstants.UkrlpPrimaryVerificationSource);

            question.Should().NotBeNull();
            question.Value.Should().Be(VerificationAuthorities.CompaniesHouseAuthority);
        }
        public async Task <IActionResult> RefreshDirectorsPscs(Guid applicationId, string ukprn, string companyNumber)
        {
            try
            {
                _logger.LogInformation($"RefreshDirectorsPscs: Retrieving company details applicationId {applicationId} | Company Number : {companyNumber}");
                var timer = new Stopwatch();
                timer.Start();
                var companyDetails = await _companiesHouseApiClient.GetCompanyDetails(companyNumber);

                var timeToCallCompanyDetails = $"{timer.ElapsedMilliseconds} ms";

                switch (companyDetails.Status)
                {
                case CompaniesHouseSummary.ServiceUnavailable:
                    _logger.LogInformation($"Issue refreshing directors/pscs - applicationId {applicationId} | Company Number : {companyNumber} | Status : Service Unavailable");
                    return(RedirectToAction("CompaniesHouseNotAvailable", "RoatpShutterPages"));

                case CompaniesHouseSummary.CompanyStatusNotFound:
                    _logger.LogInformation(
                        $"Issue refreshing directors/pscs - applicationId {applicationId} | Company Number : {companyNumber} | Status : Company Status Not Found");
                    return(RedirectToAction("CompanyNotFoundRefresh", "RoatpShutterPages", new { companyNumber }));
                }

                if (!CompaniesHouseValidator.CompaniesHouseStatusValid(ukprn, companyDetails.Status, _logger))
                {
                    _logger.LogInformation($"Issue refreshing directors/pscs - applicationId {applicationId} | UKPRN : {ukprn} | Status : Companies House status not valid: {companyDetails.Status}");
                    return(RedirectToAction("CompanyNotFoundRefresh", "RoatpShutterPages", new { companyNumber }));
                }

                var applicationDetails = new Domain.Roatp.ApplicationDetails {
                    CompanySummary = companyDetails
                };

                _logger.LogInformation($"RefreshDirectorsPscs: updating organisation directors/pscs applicationId {applicationId}");

                var success = await _organisationApiClient.UpdateDirectorsAndPscs(ukprn, companyDetails.Directors, companyDetails.PersonsWithSignificantControl, User.GetUserId());

                if (!success)
                {
                    _logger.LogInformation($"Organisation director/pscs update failed - applicationId {applicationId}");
                    return(RedirectToAction("CompaniesHouseNotAvailable", "RoatpShutterPages"));
                }

                var directorsAnswers = RoatpPreambleQuestionBuilder.CreateCompaniesHouseWhosInControlQuestions(applicationDetails);

                _logger.LogInformation($"RefreshDirectorsPscs: resetting page answers for companies, applicationId {applicationId}");
                var resetSection1_3 = _qnaApiClient.ResetPageAnswersBySequenceAndSectionNumber(applicationId, RoatpWorkflowSequenceIds.YourOrganisation, RoatpWorkflowSectionIds.YourOrganisation.WhosInControl, RoatpWorkflowPageIds.WhosInControl.CompaniesHouseStartPage);
                var resetSection3_4 = _qnaApiClient.ResetPageAnswersBySection(applicationId, RoatpWorkflowSequenceIds.CriminalComplianceChecks, RoatpWorkflowSectionIds.CriminalComplianceChecks.CheckOnWhosInControl);
                await Task.WhenAll(resetSection1_3, resetSection3_4);

                _logger.LogInformation($"RefreshDirectorsPscs: updating page answers for companies, applicationId {applicationId}");
                await _qnaApiClient.UpdatePageAnswers(applicationId, RoatpWorkflowSequenceIds.YourOrganisation, RoatpWorkflowSectionIds.YourOrganisation.WhosInControl, RoatpWorkflowPageIds.WhosInControl.CompaniesHouseStartPage, directorsAnswers.ToList <Answer>());

                var timeToDoEntireCall = $"{timer.ElapsedMilliseconds} ms";
                timer.Stop();
                _logger.LogInformation($"RefreshDirectorsPscs: all updates completed for {applicationId} - entire call timespan: {timeToDoEntireCall}, Company call timespan: {timeToCallCompanyDetails}");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Error when processing directors/pscs - applicationId {applicationId}");
                return(RedirectToAction("CompaniesHouseNotAvailable", "RoatpShutterPages"));
            }

            return(RedirectToAction("StartPage", "RoatpWhosInControlApplication", new { applicationId }));
        }
Esempio n. 26
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
            });
        }