コード例 #1
0
 public void Upvote(IVotable votable)
 {
     Badges.Add(Badge.Supporter);
     votable.Upvote(this);
 }
コード例 #2
0
ファイル: VoteButton.cs プロジェクト: HsFearless/StudyBuddy
        public void AfterClick()
        {
            if (toUpvote == previousToUpvote)
            {
                return;
            }


            //if (previousToUpvote == true)
            //{
            //    toUpvote = !votable.Upvote();
            //    this.BackColor = Color.Green;
            //    this.Text = "Vote++";
            //}
            //else
            //{
            //    toUpvote = votable.TakeBackUpvote();
            //    this.BackColor = Color.MediumSlateBlue;
            //    this.Text = "Vote --";
            //}
            //previousToUpvote = !toUpvote;


            //MessageBox.Show("Test");
            if (toUpvote)
            {
                try
                {
                    if (!votable.Upvote())
                    {
                        MessageBox.Show(votable.VoteErrorMessage());
                    }
                    else
                    {
                        AfterUpvote();
                    }
                }
                catch (exceptions.DoneBefore) //^exceptions
                {
                    AfterUpvote();
                    MessageBox.Show("You have already upvoted it!");
                }
            }//still upvote
            else
            { //take back upvote
                if (!votable.TakeBackUpvote())
                {
                    if (votable.GetError().no == dataNeeds.ErrorCode.NOT_FOUND)
                    {
                        MessageBox.Show("Your vote did not exist");
                        AfterTakeBackUpvote();
                    }
                    else
                    {
                        MessageBox.Show(votable.VoteErrorMessage());
                    }
                }
                else
                {
                    AfterTakeBackUpvote();
                }
            }
        }