Exemplo n.º 1
0
        /// <summary>
        /// Votes for answers
        /// </summary>
        /// <param name="answerid">Answer Id</param>
        /// <param name="vote">Vote</param>
        /// <returns></returns>
        public ActionResult VoteForAnswer(int answerid, int vote)
        {
            if (!Request.IsAuthenticated)
            {
                //Check if the user logged in
                return Json(Resources.Global.YouHaveToLoginBeforeVote);
            }
            else
            {
                var vman = new VoteManager();
                //Check if the user already voted for this answer
                bool isVoted = vman.IsVotedForAnswer(answerid, WebSecurity.GetUserId(User.Identity.Name));
                if (isVoted)
                {
                    return Json(Resources.Global.YouAlreadyVotedForThisAnswer);
                }

                //Check if the user want to vote for his own question
                var aman = new AnswerManager();
                if (aman.GetAnswer(answerid).UserId == WebSecurity.GetUserId(User.Identity.Name))
                {
                    return Json(Resources.Global.YouCantVoteForYourOwnAnswer);
                }
                //Store the vote
                vman.VoteAnswer(answerid, WebSecurity.GetUserId(User.Identity.Name), vote);

                return Json(aman.GetVote(answerid));

            }
        }