Esempio n. 1
0
        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
        }
Esempio n. 2
0
        public IActionResult Demographics()
        {
            VoterDemographicsDataModel data  = _Context.Demographics.Find(_UserManager.GetUserId(User));
            VoterDemographicsViewModel model = new VoterDemographicsViewModel(data);

            return(View(model));
        }
 public void Update(VoterDemographicsViewModel model)
 {
     Party          = model.Party;
     Ethnicity      = model.Ethnicity;
     Sex            = model.Sex;
     IncomeRange    = model.IncomeRange;
     VoterReadiness = model.VoterReadiness;
 }
 public VoterDemographicsDataModel(string userId, VoterDemographicsViewModel model)
 {
     UserId = userId;
     Update(model);
 }