示例#1
0
 protected void down_Click(object sender, EventArgs e)
 {
     try
     {
         Vote o = Vote.FindOne(
             Expression.Eq("VotedBy", Operator.Current),
             Expression.Eq("QuizItem", _question),
             Expression.Eq("Score", -1));
         if (o != null)
         {
             // User has voted this BEFORE. Therefore removing old vote...
             o.Delete();
             count.Text    = _question.GetScore().ToString();
             down.CssClass = "down";
             up.CssClass   = "up";
             Highlight(down);
         }
         else
         {
             CreateVoteForCurrent(false);
         }
     }
     catch (Exception err)
     {
         ShowError(err.Message);
     }
 }
示例#2
0
    protected void VoteAnswerDown(object sender, EventArgs e)
    {
        int idOfQuizItem = GetIdOfAnswer(sender as System.Web.UI.Control);

        try
        {
            QuizItem item = QuizItem.Find(idOfQuizItem);
            Vote     o    = Vote.FindOne(
                Expression.Eq("VotedBy", Operator.Current),
                Expression.Eq("QuizItem", item),
                Expression.Eq("Score", -1));
            if (o != null)
            {
                o.Delete();
                FindUpLinkButtonForAnswer(sender as System.Web.UI.Control).CssClass   = "up";
                FindDownLinkButtonForAnswer(sender as System.Web.UI.Control).CssClass = "down";
            }
            else
            {
                Vote v = new Vote();
                v.QuizItem = item;
                v.Score    = -1;
                v.VotedBy  = Operator.Current;
                v.Save();
                FindUpLinkButtonForAnswer(sender as System.Web.UI.Control).CssClass   = "up";
                FindDownLinkButtonForAnswer(sender as System.Web.UI.Control).CssClass = "downVoted";
            }
            FindLabelForAnswer(sender as System.Web.UI.Control).Text = QuizItem.Find(idOfQuizItem).Score.ToString();
        }
        catch (Exception err)
        {
            ShowError(err.Message);
        }
    }