コード例 #1
0
        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);
        }
コード例 #2
0
        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 }));
        }
コード例 #3
0
        public async Task <IActionResult> Index(int id)
        {
            PollVotingModel displayModel = await _modelPopulator.PopulatePollAndOptionsForVoting(id);

            return(View(displayModel));
        }