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())); }
private PollModel GetPollModel(Poll poll) { return(new PollModel { Poll = poll, Votes = poll == null ? null : _pollsQuery.GetPollAnswerVotes(poll.Id) }); }
private void AssertVotes(Poll poll, params int[] expectedVotes) { var votes = _pollsQuery.GetPollAnswerVotes(poll.Id); Assert.AreEqual(expectedVotes.Length, votes.Count); for (var index = 0; index < expectedVotes.Length; ++index) { Assert.AreEqual(expectedVotes[index], votes[poll.Answers[index].Id]); } }