public async Task <PollVotingModel> PopulatePollAndOptionsForVoting(int pollId) { PollVotingModel model = new PollVotingModel(); model.Poll = await _pollRoutine.GetBasicPoll(pollId); model.Options = await _pollRoutine.GetPollOptionsForVoting(pollId); return(model); }
public async Task <IActionResult> Vote(PollVotingModel pollVotingModel) { int id = pollVotingModel.Poll.Id; if (ModelState.IsValid) { List <VoteModel> votes = _modelPopulator.TransformRawOptionDataToVotes(pollVotingModel.VoterName, pollVotingModel.Options); if (votes.Count == 0) { return(RedirectToAction("ErrorVoting", new { id })); } else { await _votingRoutine.SaveVotes(votes); return(RedirectToAction("SuccessVoting", new { id })); } } return(RedirectToAction("Index", new { id })); }
public async Task <IActionResult> Index(int id) { PollVotingModel displayModel = await _modelPopulator.PopulatePollAndOptionsForVoting(id); return(View(displayModel)); }