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); } }
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); } }
protected string GetDownCssClassIfVoted(int id) { QuizItem quiz = QuizItem.Find(id); Vote hasVoted = Vote.FindOne( Expression.Eq("VotedBy", Operator.Current), Expression.Eq("QuizItem", quiz), Expression.Eq("Score", -1)); if (hasVoted != null) { return("downVoted"); } return("down"); }
private void SetCssClassIfCurrentOperatorHasVoted() { // Setting CSS classes of voters for QUESTION up.CssClass = "up"; down.CssClass = "down"; if (Operator.Current != null) { Vote hasVoted = Vote.FindOne( Expression.Eq("VotedBy", Operator.Current), Expression.Eq("QuizItem", _question)); if (hasVoted != null) { if (hasVoted.Score > 0) { up.CssClass = "upVoted"; } else { down.CssClass = "downVoted"; } } } }