コード例 #1
0
        private void ValidateAndFormatSearchPensionRegulatorByAornViewModel(SearchPensionRegulatorByAornViewModel viewModel)
        {
            var errors = new Dictionary <string, string>();

            viewModel.Aorn    = viewModel.Aorn?.ToUpper().Trim();
            viewModel.PayeRef = viewModel.PayeRef?.ToUpper().Trim();

            if (string.IsNullOrWhiteSpace(viewModel.Aorn))
            {
                errors.Add(nameof(viewModel.Aorn), "Enter your reference number to continue");
            }
            else if (!_aornRegex.IsMatch(viewModel.Aorn.ToUpper().Trim()))
            {
                errors.Add(nameof(viewModel.Aorn), "Enter an accounts office reference number in the correct format");
            }

            if (string.IsNullOrWhiteSpace(viewModel.PayeRef))
            {
                errors.Add(nameof(viewModel.PayeRef), "Enter your PAYE scheme to continue");
            }
            else if (!_payeRegex.IsMatch(viewModel.PayeRef))
            {
                errors.Add(nameof(viewModel.PayeRef), "Enter a PAYE scheme number in the correct format");
            }
            else if (viewModel.PayeRef[3] != '/')
            {
                viewModel.PayeRef = viewModel.PayeRef.Insert(3, "/");
            }

            viewModel.AddErrorsFromDictionary(errors);
        }
コード例 #2
0
        public async Task <ActionResult> SearchPensionRegulatorByAorn(SearchPensionRegulatorByAornViewModel viewModel)
        {
            ValidateAndFormatSearchPensionRegulatorByAornViewModel(viewModel);

            if (!viewModel.Valid)
            {
                return(View(ControllerConstants.SearchUsingAornViewName, viewModel));
            }

            return(await PerformSearchPensionRegulatorByAorn(viewModel));
        }
コード例 #3
0
        private async Task <ActionResult> PerformSearchPensionRegulatorByAorn(SearchPensionRegulatorByAornViewModel viewModel)
        {
            var userRef = OwinWrapper.GetClaimValue(ControllerConstants.UserRefClaimKeyName);
            var model   = await _searchPensionRegulatorOrchestrator.GetOrganisationsByAorn(viewModel.Aorn, viewModel.PayeRef);

            await _mediatr.SendAsync(new UpdateUserAornLockRequest
            {
                UserRef = userRef,
                Success = model.Data.Results.Count > 0
            });

            switch (model.Data.Results.Count)
            {
            case 0:
            {
                var aornLock = await _mediatr.SendAsync(new GetUserAornLockRequest
                    {
                        UserRef = userRef
                    });

                viewModel.IsLocked          = aornLock.UserAornStatus.IsLocked;
                viewModel.RemainingAttempts = aornLock.UserAornStatus.RemainingAttempts;
                viewModel.AllowedAttempts   = aornLock.UserAornStatus.AllowedAttempts;
                viewModel.RemainingLock     = aornLock.UserAornStatus.RemainingLock;

                return(View(ControllerConstants.SearchUsingAornViewName, viewModel));
            }

            case 1:
            {
                if (await CheckIfPayeSchemeAlreadyInUse(viewModel.PayeRef))
                {
                    return(RedirectToAction(ControllerConstants.PayeErrorActionName, ControllerConstants.EmployerAccountControllerName, new { NotFound = false }));
                }
                await SavePensionRegulatorDataIfItHasAValidName(model.Data.Results.First(), true, false, viewModel.Aorn, viewModel.PayeRef);

                return(RedirectToAction(ControllerConstants.SummaryActionName, ControllerConstants.EmployerAccountControllerName));
            }

            default:
            {
                if (await CheckIfPayeSchemeAlreadyInUse(viewModel.PayeRef))
                {
                    return(RedirectToAction(ControllerConstants.PayeErrorActionName, ControllerConstants.EmployerAccountControllerName, new { NotFound = false }));
                }
                await SavePayeDetails(viewModel.Aorn, viewModel.PayeRef);

                return(View(ControllerConstants.SearchPensionRegulatorResultsViewName, model.Data));
            }
            }
        }