/// <summary> /// Votes for a questions /// </summary> /// <param name="questionid">Question Id</param> /// <param name="vote">Vote: +1 or -1</param> /// <returns></returns> public ActionResult VoteForQuestion(int questionid, int vote) { if (!Request.IsAuthenticated) { //If the user is not logged in, we create an error message return Json(Resources.Global.YouHaveToLoginBeforeVote); } else { //We check if the user already voted for this question var vman = new VoteManager(); bool isvoted = vman.IsVotedForQuestion(questionid, WebSecurity.GetUserId(User.Identity.Name)); if (isvoted) { return Json(Resources.Global.YouAlreadyVotedForThisQuestion); } //We check if the user want to vote for his own question var qman = new QuestionManager(); if (qman.GetQuestion(questionid).UserId == WebSecurity.GetUserId(User.Identity.Name)) { return Json(Resources.Global.YouCantVoteForYourOwnQuestion); } //We store the vote vman.Vote(questionid, WebSecurity.GetUserId(User.Identity.Name), vote); //We returns the new vote of the question return Json(qman.GetVote(questionid)); } }