Exemple #1
0
        public JsonResult VoteComment(int commentId, int typeOfVote)
        {
            int dailyVotingQuota            = MvcApplication.DailyVotingQuota;
            var loggedInUser                = User.Identity.Name;
            var userCcp                     = Karma.CommentKarma(loggedInUser);
            var scaledDailyVotingQuota      = Math.Max(dailyVotingQuota, userCcp / 2);
            var totalVotesUsedInPast24Hours = Utils.User.TotalVotesUsedInPast24Hours(User.Identity.Name);

            switch (typeOfVote)
            {
            case 1:
                if (userCcp >= 20)
                {
                    if (totalVotesUsedInPast24Hours < scaledDailyVotingQuota)
                    {
                        // perform upvoting or resetting
                        VotingComments.UpvoteComment(commentId, loggedInUser, IpHash.CreateHash(Utils.User.UserIpAddress(Request)));
                    }
                }
                else if (totalVotesUsedInPast24Hours < 11)
                {
                    // perform upvoting or resetting even if user has no CCP but only allow 10 votes per 24 hours
                    VotingComments.UpvoteComment(commentId, loggedInUser, IpHash.CreateHash(Utils.User.UserIpAddress(Request)));
                }
                break;

            case -1:
                if (userCcp >= 100)
                {
                    if (totalVotesUsedInPast24Hours < scaledDailyVotingQuota)
                    {
                        // perform downvoting or resetting
                        VotingComments.DownvoteComment(commentId, loggedInUser, IpHash.CreateHash(Utils.User.UserIpAddress(Request)));
                    }
                }
                break;
            }

            Response.StatusCode = 200;
            return(Json("Voting ok", JsonRequestBehavior.AllowGet));
        }
        public JsonResult VoteComment(int commentId, int typeOfVote)
        {
            string loggedInUser = User.Identity.Name;

            if (typeOfVote == 1)
            {
                // perform upvoting or resetting
                VotingComments.UpvoteComment(commentId, loggedInUser);
            }
            else if (typeOfVote == -1)
            {
                // ignore downvote if user comment karma is below certain treshold
                if (Karma.CommentKarma(loggedInUser) > 100)
                {
                    // perform downvoting or resetting
                    VotingComments.DownvoteComment(commentId, loggedInUser);
                }
            }
            Response.StatusCode = 200;
            return(Json("Voting ok", JsonRequestBehavior.AllowGet));
        }