public void Validator_returns_false_for_missing_ukprn(string ukprn)
        {
            bool isValid = UkprnValidator.IsValidUkprn(ukprn, out var ukprnValue);

            isValid.Should().BeFalse();
            ukprnValue.Should().Be(0);
        }
        public void Validator_returns_true_for_a_valid_ukprn()
        {
            string ukprn = "10002000";

            bool isValid = UkprnValidator.IsValidUkprn(ukprn, out var ukprnValue);

            isValid.Should().BeTrue();
            ukprnValue.Should().Be(10002000);
        }
示例#3
0
        public async Task <IActionResult> SearchByUkprn(SearchByUkprnViewModel model)
        {
            int    ukprn             = 0;
            string validationMessage = string.Empty;

            if (string.IsNullOrWhiteSpace(model.UKPRN))
            {
                validationMessage = UkprnValidationMessages.MissingUkprn;
            }
            else
            {
                bool isValidUkprn = UkprnValidator.IsValidUkprn(model.UKPRN, out ukprn);
                if (!isValidUkprn)
                {
                    validationMessage = UkprnValidationMessages.InvalidUkprn;
                }
                else if (!await _allowedUkprnValidator.CanUkprnStartApplication(ukprn))
                {
                    validationMessage = UkprnValidationMessages.NotWhitelistedUkprn;
                }
            }

            if (!string.IsNullOrEmpty(validationMessage))
            {
                model.ErrorMessages = new List <ValidationErrorDetail>
                {
                    new ValidationErrorDetail {
                        Field = "UKPRN", ErrorMessage = validationMessage
                    }
                };

                return(View("~/Views/Roatp/EnterApplicationUkprn.cshtml", model));
            }

            var ukprnInReapplication = await _reapplicationCheckService.ReapplicationUkprnForUser(User.GetSignInId());

            if (ukprnInReapplication != null && ukprnInReapplication != ukprn.ToString())
            {
                return(RedirectToAction("ReapplicationDifferentUkprn", "RoatpShutterPages"));
            }

            var isApplicationInFlightWithDifferentUser = await _reapplicationCheckService.ApplicationInFlightWithDifferentUser(User.GetSignInId(),
                                                                                                                               model.UKPRN);


            if (isApplicationInFlightWithDifferentUser)
            {
                return(RedirectToAction("ApplicationInProgress", new { UKPRN = model.UKPRN }));
            }

            var ukrlpLookupResults = await _ukrlpApiClient.GetTrainingProviderByUkprn(ukprn);

            if (ukrlpLookupResults?.Results is null || !ukrlpLookupResults.Success)
            {
                return(RedirectToAction("UkrlpNotAvailable", "RoatpShutterPages"));
            }

            if (ukrlpLookupResults.Results.Any())
            {
                var applicationDetails = new ApplicationDetails
                {
                    UKPRN = ukprn,
                    UkrlpLookupDetails = ukrlpLookupResults.Results.FirstOrDefault()
                };

                _sessionService.Set(ApplicationDetailsKey, applicationDetails);

                return(RedirectToAction("ConfirmOrganisation"));
            }
            else
            {
                var applicationDetails = new ApplicationDetails
                {
                    UKPRN = ukprn
                };

                _sessionService.Set(ApplicationDetailsKey, applicationDetails);
                return(RedirectToAction("UkprnNotFound", "RoatpShutterPages"));
            }
        }
示例#4
0
        public async Task <IActionResult> SearchByUkprn(SearchByUkprnViewModel model)
        {
            int    ukprn             = 0;
            string validationMessage = string.Empty;

            if (string.IsNullOrWhiteSpace(model.UKPRN))
            {
                validationMessage = UkprnValidationMessages.MissingUkprn;
            }
            else
            {
                bool isValidUkprn = UkprnValidator.IsValidUkprn(model.UKPRN, out ukprn);
                if (!isValidUkprn)
                {
                    validationMessage = UkprnValidationMessages.InvalidUkprn;
                }
                else if (!await _ukprnWhitelistValidator.IsWhitelistedUkprn(ukprn))
                {
                    validationMessage = UkprnValidationMessages.NotWhitelistedUkprn;
                }
            }

            if (!string.IsNullOrEmpty(validationMessage))
            {
                model.ErrorMessages = new List <ValidationErrorDetail>
                {
                    new ValidationErrorDetail {
                        Field = "UKPRN", ErrorMessage = validationMessage
                    }
                };

                return(View("~/Views/Roatp/EnterApplicationUkprn.cshtml", model));
            }

            var ukrlpLookupResults = await _ukrlpApiClient.GetTrainingProviderByUkprn(ukprn);

            if (ukrlpLookupResults?.Results is null || !ukrlpLookupResults.Success)
            {
                return(RedirectToAction("UkrlpNotAvailable", "RoatpShutterPages"));
            }

            if (ukrlpLookupResults.Results.Any())
            {
                var applicationDetails = new ApplicationDetails
                {
                    UKPRN = ukprn,
                    UkrlpLookupDetails = ukrlpLookupResults.Results.FirstOrDefault()
                };

                _sessionService.Set(ApplicationDetailsKey, applicationDetails);

                return(RedirectToAction("ConfirmOrganisation"));
            }
            else
            {
                var applicationDetails = new ApplicationDetails
                {
                    UKPRN = ukprn
                };

                _sessionService.Set(ApplicationDetailsKey, applicationDetails);
                return(RedirectToAction("UkprnNotFound", "RoatpShutterPages"));
            }
        }
        public void Validator_returns_false_for_invalid_ukprn(string ukprn)
        {
            bool isValid = UkprnValidator.IsValidUkprn(ukprn, out _);

            isValid.Should().BeFalse();
        }