public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Poll).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PollExists(Poll.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } for (int i = 0; i < SelectedAnswers.Count; ++i) { PollChoice pc = await _context.PollChoices.SingleOrDefaultAsync(c => c.ID == SelectedAnswers[i]); // grab poll choice from db that matches selected answer pc.VoteTally += 1; // increment the vote tally since the user selected it _context.Attach(pc).State = EntityState.Modified; // declare that the poll choice has been modified await _context.SaveChangesAsync(); // save changes to database } return(RedirectToPage("./VoteConfirmation")); }