Пример #1
0
 public void Handle(VoteAdded message)
 {
     _db.Comments.Update(message.CommentId, comment =>
     {
         comment.Votes.Add(new VoteDocument()
         {
             Content      = message.Content,
             UserId       = message.UserId,
             VoteId       = message.VoteId,
             UserDocument = _db.Users.GetById(message.UserId)
         });
     });
 }
Пример #2
0
        public void ExecuteVote(string poll, string user, string option)
        {
            if (context.Database.Update <PollVote>().Set(p => p.Vote == option).Where(p => p.Poll == poll && p.User == user).Execute() == 0)
            {
                context.Database.Insert <PollVote>().Columns(p => p.Poll, p => p.User, p => p.Vote).Values(poll, user, option).Execute();
            }

            if (ShowPollAfterVote)
            {
                ShowPoll(poll);
            }

            // if this is a vote for a new poll, include poll in polls to be shown
            if (availablepolls.All(p => p != poll))
            {
                ReloadAvailablePolls();
            }

            VoteAdded?.Invoke(new PollVote {
                Poll = poll,
                User = user,
                Vote = option
            });
        }