Esempio n. 1
0
        public void TestVotes()
        {
            var poll = CreatePoll(0, 4, true);

            var userId1 = Guid.NewGuid();
            var userId2 = Guid.NewGuid();
            var userId3 = Guid.NewGuid();

            AssertVotes(poll, 0, 0, 0, 0);

            _pollsCommand.CreatePollAnswerVote(new PollAnswerVote {
                AnswerId = poll.Answers[0].Id, UserId = userId1
            });
            AssertVotes(poll, 1, 0, 0, 0);

            _pollsCommand.CreatePollAnswerVote(new PollAnswerVote {
                AnswerId = poll.Answers[0].Id, UserId = userId1
            });
            AssertVotes(poll, 1, 0, 0, 0);

            _pollsCommand.CreatePollAnswerVote(new PollAnswerVote {
                AnswerId = poll.Answers[1].Id, UserId = userId1
            });
            AssertVotes(poll, 1, 0, 0, 0);

            _pollsCommand.CreatePollAnswerVote(new PollAnswerVote {
                AnswerId = poll.Answers[2].Id, UserId = userId2
            });
            AssertVotes(poll, 1, 0, 1, 0);

            _pollsCommand.CreatePollAnswerVote(new PollAnswerVote {
                AnswerId = poll.Answers[2].Id, UserId = userId3
            });
            AssertVotes(poll, 1, 0, 2, 0);
        }
Esempio n. 2
0
        public ActionResult Vote(byte voteId)
        {
            try
            {
                var poll = _pollsQuery.GetActivePoll();
                if (poll != null)
                {
                    if (voteId < poll.Answers.Count)
                    {
                        var userId = CurrentMember == null ? CurrentAnonymousUser.Id : CurrentMember.Id;
                        _pollsCommand.CreatePollAnswerVote(new PollAnswerVote {
                            AnswerId = poll.Answers[voteId].Id, UserId = userId
                        });
                    }
                }

                return(PartialView("ActivePoll", new PollModel {
                    Poll = poll, Votes = poll != null ? _pollsQuery.GetPollAnswerVotes(poll.Id) : null
                }));
            }
            catch (UserException ex)
            {
                ModelState.AddModelError(ex, new StandardErrorHandler());
            }

            return(Json(new JsonResponseModel()));
        }