コード例 #1
0
        public async Task <IActionResult> Vote(int pollId, int?answer)
        {
            var poll        = _polls.GetPollById(pollId); // lets me include reference to poll & answer in newVote
            var currentUser = await _userManager.GetUserAsync(User);

            if (answer == null)
            {
                ModelState.AddModelError("", "You have to choose an answer.");
            }

            if (_votes.CheckIfUserAlreadyVoted(pollId, currentUser))
            {
                ModelState.AddModelError("", "You have already voted in this poll.");
            }

            if (ModelState.IsValid)
            {
                Vote newVote = new Vote
                {
                    User     = currentUser,
                    PollId   = pollId,
                    AnswerId = answer.Value
                };

                _votes.AddVote(newVote);
                return(RedirectToAction(nameof(Vote), new { pollid = pollId, showResults = true }));
            }

            var model = new PollVoteViewModel
            {
                PollId   = poll.PollId,
                Question = poll.Question,
                Answers  = poll.Answers.ToList()
            };

            return(View("~/Features/Polls/VoteForm.cshtml", model));
        }
コード例 #2
0
ファイル: VoteBLL.cs プロジェクト: xuefuruanjian/ems
 public static int AddVote(VoteInfo vote)
 {
     vote.ID = dal.AddVote(vote);
     return(vote.ID);
 }
コード例 #3
0
 public Vote AddVote(Vote vote)
 {
     return(voteService.AddVote(vote));
 }
コード例 #4
0
 /// <summary>
 /// 增加一条投票数据
 /// </summary>
 /// <param name="vote">投票模型变量</param>
 public static int AddVote(VoteInfo vote)
 {
     vote.ID = dal.AddVote(vote);
     CacheHelper.Remove(cacheKey);
     return(vote.ID);
 }