public IActionResult ChooseACentre()
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Home"));
            }

            ChooseACentreViewModel model = TempData.Peek <ChooseACentreViewModel>();

            return(View("ChooseACentre", model));
        }
        public async Task <IActionResult> Index(LoginViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index", model));
            }

            var loginResult = loginService.AttemptLogin(model.Username !.Trim(), model.Password !);

            var(adminLoginDetails, delegateLoginDetails) = GetLoginDetails(loginResult.Accounts);
            switch (loginResult.LoginAttemptResult)
            {
            case LoginAttemptResult.InvalidCredentials:
                ModelState.AddModelError("Password", "The credentials you have entered are incorrect");
                return(View("Index", model));

            case LoginAttemptResult.AccountLocked:
                return(RedirectToAction("AccountLocked"));

            case LoginAttemptResult.AccountNotApproved:
                return(View("AccountNotApproved"));

            case LoginAttemptResult.InactiveCentre:
                return(View("CentreInactive"));

            case LoginAttemptResult.LogIntoSingleCentre:
                sessionService.StartAdminSession(adminLoginDetails?.Id);
                return(await LogIn(
                           adminLoginDetails,
                           delegateLoginDetails.FirstOrDefault(),
                           model.RememberMe,
                           model.ReturnUrl
                           ));

            case LoginAttemptResult.ChooseACentre:
                var chooseACentreViewModel = new ChooseACentreViewModel(loginResult.AvailableCentres);
                SetTempDataForChooseACentre(
                    model.RememberMe,
                    adminLoginDetails,
                    delegateLoginDetails,
                    chooseACentreViewModel,
                    model.ReturnUrl
                    );
                return(RedirectToAction("ChooseACentre", "Login"));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 private void SetTempDataForChooseACentre(
     bool rememberMe,
     AdminLoginDetails?adminLoginDetails,
     List <DelegateLoginDetails> delegateLoginDetails,
     ChooseACentreViewModel chooseACentreViewModel,
     string?returnUrl
     )
 {
     TempData.Clear();
     TempData["RememberMe"] = rememberMe;
     TempData.Set(adminLoginDetails);
     TempData.Set(delegateLoginDetails);
     TempData.Set(chooseACentreViewModel);
     TempData["ReturnUrl"] = returnUrl;
 }