Exemplo n.º 1
0
        public AddUkprnToAllowProvidersListValidator(IRoatpApplicationApiClient applyApiClient)
        {
            _applyApiClient = applyApiClient;

            RuleFor(x => x.Ukprn).NotEmpty().WithMessage("Enter a UKPRN")
            .DependentRules(() =>
            {
                RuleFor(x => x.Ukprn).CustomAsync(async(ukprnInput, context, cancellationToken) =>
                {
                    if (!int.TryParse(ukprnInput, out var ukprn))
                    {
                        context.AddFailure("Enter a valid UKPRN");
                    }
                    else if (ukprn < 10000000 || ukprn > 19999999)
                    {
                        context.AddFailure("Enter a valid UKPRN using 8 numbers");
                    }
                    else if (await _applyApiClient.GetAllowedProviderDetails(ukprn) != null)
                    {
                        context.AddFailure($"UKPRN {ukprn} exists in the allow list");
                    }
                });
            });

            RuleFor(x => x.StartDate).NotEmpty().WithMessage("Select an invitation start date")
            .DependentRules(() =>
            {
                RuleFor(x => x.StartDate).LessThanOrEqualTo(x => x.EndDate)
                .When(x => x.StartDate.HasValue && x.EndDate.HasValue)
                .WithMessage("The invitation end date must be on or after the start date");
            });

            RuleFor(x => x.EndDate).NotEmpty().WithMessage("Select an invitation end date");
        }
        public async Task <IActionResult> ConfirmRemoveUkprn(string ukprn)
        {
            if (!int.TryParse(ukprn, out var providerUkprn))
            {
                return(RedirectToAction(nameof(Index)));
            }

            var model = new RemoveUkprnFromAllowedProvidersListViewModel
            {
                AllowedProvider = await _applyApiClient.GetAllowedProviderDetails(providerUkprn)
            };

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