示例#1
0
        public IActionResult FinalizeRegistration()
        {
            string userId = _UserManager.GetUserId(User);
            VoterRegistrationDataModel registrationData = _Context.Registration.Find(userId);
            VoterAddressDataModel      addressData      = _Context.Address.Find(userId);
            VoterDemographicsDataModel demographicsData = _Context.Demographics.Find(userId);

            VoterFinalizeRegistrationViewModel model = new VoterFinalizeRegistrationViewModel(registrationData, addressData, demographicsData);

            if (registrationData == null || addressData == null || demographicsData == null)
            {
                // TODO change to some error page -- not done with other registration
                return(View(model));
            }
            return(View(model));
        }
示例#2
0
        public async Task <IActionResult> FinalizeRegistrationAsync(VoterFinalizeRegistrationViewModel model)
        {
            string userId = _UserManager.GetUserId(User);
            VoterRegistrationDataModel registrationData = _Context.Registration.Find(userId);
            VoterAddressDataModel      addressData      = _Context.Address.Find(userId);
            VoterDemographicsDataModel demographicsData = _Context.Demographics.Find(userId);

            if (registrationData == null || addressData == null || demographicsData == null)
            {
                // TODO change to some error page -- not done with other registration
                return(RedirectToAction(nameof(Dashboard)));
            }

            ApplicationUser user = await _UserManager.GetUserAsync(User);

            _UserManager.AddToRoleAsync(user, "RegisteredVoter").Wait();
            _UserManager.RemoveFromRoleAsync(user, "GenericUser").Wait();

            // this is needed to update the cookie so it has the correct roles
            // otherwise the user will sill have access as a genericUser.
            _SignInManager.RefreshSignInAsync(user).Wait();

            return(RedirectToAction(nameof(VoterController.Dashboard), nameof(VoterController).RemoveController()));
        }