public async Task <IActionResult> DemographicsAsync(VoterDemographicsViewModel model) { if (ModelState.IsValid) { string userId = _UserManager.GetUserId(User); VoterDemographicsDataModel demographics = await _Context.Demographics.FindAsync(userId); if (demographics == null) { demographics = new VoterDemographicsDataModel(userId, model); _Context.Demographics.Add(demographics); } else { demographics.Update(model); _Context.Demographics.Update(demographics); } await _Context.SaveChangesAsync(); return(RedirectToAction(nameof(Dashboard))); } return(View("Demographics", model)); //Index view }
public IActionResult Demographics() { VoterDemographicsDataModel data = _Context.Demographics.Find(_UserManager.GetUserId(User)); VoterDemographicsViewModel model = new VoterDemographicsViewModel(data); return(View(model)); }
public VoterDemographicsViewModel(VoterDemographicsDataModel data) { if (data == null) { return; } Party = data.Party; Ethnicity = data.Ethnicity; Sex = data.Sex; IncomeRange = data.IncomeRange; VoterReadiness = data.VoterReadiness; }
public IActionResult Dashboard() { string userId = _UserManager.GetUserId(User); VoterRegistrationDataModel registrationData = _Context.Registration.Find(userId); VoterAddressDataModel addressData = _Context.Address.Find(userId); VoterDemographicsDataModel demographicsData = _Context.Demographics.Find(userId); VoterDashboardViewModel model = new VoterDashboardViewModel( registrationData != null, addressData != null, demographicsData != null); return(View(model)); }
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)); }
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())); }
public VoterFinalizeRegistrationViewModel(VoterRegistrationDataModel registrationData, VoterAddressDataModel addressData, VoterDemographicsDataModel demographicsData) { if (registrationData == null || addressData == null || demographicsData == null) { return; } FirstName = registrationData.FirstName; LastName = registrationData.LastName; DOB = registrationData.DOB; Identification = registrationData.Identification; SSNumber = registrationData.SSNumber; AddressLineOne = addressData.AddressLineOne; AddressLineTwo = addressData.AddressLineTwo; City = addressData.City; ZipCode = addressData.ZipCode.ToString(); State = addressData.State; Party = demographicsData.Party; Ethnicity = demographicsData.Ethnicity; Sex = demographicsData.Sex; IncomeRange = demographicsData.IncomeRange; VoterReadiness = demographicsData.VoterReadiness; }