コード例 #1
0
        public async Task <IActionResult> UkrlpLookup(string ukprn)
        {
            UkprnLookupResponse providerData;

            long ukprnValue = Convert.ToInt64(ukprn);

            try
            {
                providerData = await _retryPolicy.ExecuteAsync(context => _apiClient.GetTrainingProviderByUkprn(ukprnValue), new Context());
            }
            catch (Exception ex)
            {
                _logger.LogError("Unable to retrieve results from UKRLP", ex);
                providerData = new UkprnLookupResponse
                {
                    Success = false,
                    Results = new List <ProviderDetails>()
                };
            }
            return(Ok(providerData));
        }
コード例 #2
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"));
            }
        }
コード例 #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 _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"));
            }
        }