Esempio n. 1
0
        public void Handle(PollVotedUnvoted message)
        {
            if (message.Poll.id != this.Poll.id || message.Poll.owner_id != this.Poll.owner_id)
            {
                return;
            }
            PollAnswerHeader pollAnswerHeader1 = (PollAnswerHeader)Enumerable.FirstOrDefault <PollAnswerHeader>(this.Answers, (Func <PollAnswerHeader, bool>)(a => a.Answer.id == message.AnswerHeader.Answer.id));

            if (pollAnswerHeader1 == null)
            {
                return;
            }
            if (!this.Voted)
            {
                this.Poll.answer_id = pollAnswerHeader1.Answer.id;
                ++this.Poll.votes;
                ++pollAnswerHeader1.Answer.votes;
            }
            else if (this.Poll.answer_id == pollAnswerHeader1.Answer.id)
            {
                this.Poll.answer_id = 0L;
                --this.Poll.votes;
                --pollAnswerHeader1.Answer.votes;
            }
            else
            {
                long currentAnswer = this.Poll.answer_id;
                this.Poll.answer_id = pollAnswerHeader1.Answer.id;
                ++pollAnswerHeader1.Answer.votes;
                PollAnswerHeader pollAnswerHeader2 = (PollAnswerHeader)Enumerable.FirstOrDefault <PollAnswerHeader>(this.Answers, (Func <PollAnswerHeader, bool>)(ah => ah.Answer.id == currentAnswer));
                if (pollAnswerHeader2 != null)
                {
                    --pollAnswerHeader2.Answer.votes;
                }
            }
            this.NotifyUpdates();
        }
Esempio n. 2
0
 public void VoteUnvote(PollAnswerHeader answerHeader)
 {
     if (this.IsVoting)
     {
         return;
     }
     this.IsVoting = true;
     if (!this.Voted)
     {
         this.Poll.answer_id = answerHeader.Answer.id;
         ++this.Poll.votes;
         ++answerHeader.Answer.votes;
         this.DoVote(this.Poll.answer_id);
     }
     else if (this.Poll.answer_id == answerHeader.Answer.id)
     {
         this.Poll.answer_id = 0L;
         --this.Poll.votes;
         --answerHeader.Answer.votes;
         this.DoUnvote(answerHeader.Answer.id);
     }
     else
     {
         long currentAnswer = this.Poll.answer_id;
         this.Poll.answer_id = answerHeader.Answer.id;
         ++answerHeader.Answer.votes;
         PollAnswerHeader pollAnswerHeader = (PollAnswerHeader)Enumerable.FirstOrDefault <PollAnswerHeader>(this.Answers, (Func <PollAnswerHeader, bool>)(ah => ah.Answer.id == currentAnswer));
         if (pollAnswerHeader != null)
         {
             --pollAnswerHeader.Answer.votes;
         }
         this.DoUnvoteVote(currentAnswer, this.Poll.answer_id);
     }
     this.NotifyUpdates();
     EventAggregator.Current.Publish(new PollVotedUnvoted(this.Poll, answerHeader));
 }
Esempio n. 3
0
 public PollVotedUnvoted(Poll poll, PollAnswerHeader answerHeader)
 {
     this.Poll         = poll;
     this.AnswerHeader = answerHeader;
 }