コード例 #1
0
        public async Task <ActionResult> Submitcomment([Bind(Include = "Id,CommentContent,MessageId,ParentId")] Comment comment)
        {
            comment.Date  = System.DateTime.Now;
            comment.Name  = User.Identity.Name;
            comment.Votes = 1;
            if (ModelState.IsValid)
            {
                db.Comments.Add(comment);
                await db.SaveChangesAsync();

                //get newly generated Comment ID and execute ranking and self upvoting
                Commentvotingtracker tmpVotingTracker = new Commentvotingtracker();
                tmpVotingTracker.CommentId  = comment.Id;
                tmpVotingTracker.UserName   = comment.Name;
                tmpVotingTracker.VoteStatus = 1;
                db.Commentvotingtrackers.Add(tmpVotingTracker);
                await db.SaveChangesAsync();

                string url = this.Request.UrlReferrer.AbsolutePath;
                return(Redirect(url));
            }
            else
            {
                return(View("~/Views/Help/SpeedyGonzales.cshtml"));
            }
        }
コード例 #2
0
        // submit comment upvote
        public static void UpvoteComment(int commentId, string userWhichUpvoted, string clientIpHash)
        {
            int result = CheckIfVotedComment(userWhichUpvoted, commentId);

            using (voatEntities db = new voatEntities())
            {
                Comment comment = db.Comments.Find(commentId);

                if (comment.Message.Anonymized)
                {
                    // do not execute voting, subverse is in anonymized mode
                    return;
                }

                switch (result)
                {
                // never voted before
                case 0:

                    if (comment.Name != userWhichUpvoted)
                    {
                        // check if this IP already voted on the same comment, abort voting if true
                        var ipVotedAlready = db.Commentvotingtrackers.Where(x => x.CommentId == commentId && x.ClientIpAddress == clientIpHash);
                        if (ipVotedAlready.Any())
                        {
                            return;
                        }

                        comment.Likes++;

                        // register upvote
                        var tmpVotingTracker = new Commentvotingtracker
                        {
                            CommentId       = commentId,
                            UserName        = userWhichUpvoted,
                            VoteStatus      = 1,
                            Timestamp       = DateTime.Now,
                            ClientIpAddress = clientIpHash
                        };
                        db.Commentvotingtrackers.Add(tmpVotingTracker);
                        db.SaveChanges();

                        Karma.UpdateUserCcp(comment.Name, 1);

                        Voting.SendVoteNotification(comment.Name, "upvote");
                    }

                    break;

                // downvoted before, turn downvote to upvote
                case -1:

                    if (comment.Name != userWhichUpvoted)
                    {
                        comment.Likes++;
                        comment.Dislikes--;

                        // register Turn DownVote To UpVote
                        var votingTracker = db.Commentvotingtrackers.FirstOrDefault(b => b.CommentId == commentId && b.UserName == userWhichUpvoted);

                        if (votingTracker != null)
                        {
                            votingTracker.VoteStatus = 1;
                            votingTracker.Timestamp  = DateTime.Now;
                        }
                        db.SaveChanges();

                        Karma.UpdateUserCcp(comment.Name, 2);

                        Voting.SendVoteNotification(comment.Name, "downtoupvote");
                    }

                    break;

                // upvoted before, reset
                case 1:

                    comment.Likes--;
                    db.SaveChanges();
                    Karma.UpdateUserCcp(comment.Name, -1);

                    Voting.SendVoteNotification(comment.Name, "downvote");

                    ResetCommentVote(userWhichUpvoted, commentId);

                    break;
                }
            }
        }
コード例 #3
0
        // submit submission downvote
        public static void DownvoteComment(int commentId, string userWhichDownvoted, string clientIpHash)
        {
            int result = CheckIfVotedComment(userWhichDownvoted, commentId);

            using (voatEntities db = new voatEntities())
            {
                Comment comment = db.Comments.Find(commentId);

                // do not execute downvoting, subverse is in anonymized mode
                if (comment.Message.Anonymized)
                {
                    return;
                }

                // do not execute downvoting if user has insufficient CCP for target subverse
                if (Karma.CommentKarmaForSubverse(userWhichDownvoted, comment.Message.Subverse) < comment.Message.Subverses.minimumdownvoteccp)
                {
                    return;
                }

                switch (result)
                {
                // never voted before
                case 0:

                {
                    // this user is downvoting more than upvoting, don't register the downvote
                    if (UserHelper.IsUserCommentVotingMeanie(userWhichDownvoted))
                    {
                        return;
                    }

                    // check if this IP already voted on the same comment, abort voting if true
                    var ipVotedAlready = db.Commentvotingtrackers.Where(x => x.CommentId == commentId && x.ClientIpAddress == clientIpHash);
                    if (ipVotedAlready.Any())
                    {
                        return;
                    }

                    comment.Dislikes++;

                    // register downvote
                    var tmpVotingTracker = new Commentvotingtracker
                    {
                        CommentId       = commentId,
                        UserName        = userWhichDownvoted,
                        VoteStatus      = -1,
                        Timestamp       = DateTime.Now,
                        ClientIpAddress = clientIpHash
                    };
                    db.Commentvotingtrackers.Add(tmpVotingTracker);
                    db.SaveChanges();

                    Karma.UpdateUserCcp(comment.Name, -1);

                    Voting.SendVoteNotification(comment.Name, "downvote");
                }

                break;

                // upvoted before, turn upvote to downvote
                case 1:

                {
                    comment.Likes--;
                    comment.Dislikes++;

                    //register Turn DownVote To UpVote
                    var votingTracker = db.Commentvotingtrackers.FirstOrDefault(b => b.CommentId == commentId && b.UserName == userWhichDownvoted);

                    if (votingTracker != null)
                    {
                        votingTracker.VoteStatus = -1;
                        votingTracker.Timestamp  = DateTime.Now;
                    }
                    db.SaveChanges();

                    Karma.UpdateUserCcp(comment.Name, -2);

                    Voting.SendVoteNotification(comment.Name, "uptodownvote");
                }

                break;

                // downvoted before, reset
                case -1:

                    comment.Dislikes--;
                    db.SaveChanges();

                    Karma.UpdateUserCcp(comment.Name, 1);
                    ResetCommentVote(userWhichDownvoted, commentId);

                    Voting.SendVoteNotification(comment.Name, "upvote");

                    break;
                }
            }
        }
コード例 #4
0
        // submit comment upvote
        public static void UpvoteComment(int commentId, string userWhichUpvoted)
        {
            int result = CheckIfVotedComment(userWhichUpvoted, commentId);

            using (whoaverseEntities db = new whoaverseEntities())
            {
                Comment comment = db.Comments.Find(commentId);

                if (comment.Message.Anonymized)
                {
                    // do not execute voting, subverse is in anonymized mode
                    return;
                }

                switch (result)
                {
                // never voted before
                case 0:

                    if (comment.Name != userWhichUpvoted)
                    {
                        comment.Likes++;

                        // register upvote
                        var tmpVotingTracker = new Commentvotingtracker
                        {
                            CommentId  = commentId,
                            UserName   = userWhichUpvoted,
                            VoteStatus = 1,
                            Timestamp  = DateTime.Now
                        };
                        db.Commentvotingtrackers.Add(tmpVotingTracker);
                        db.SaveChanges();

                        SendVoteNotification(comment.Name, "upvote");
                    }

                    break;

                // downvoted before, turn downvote to upvote
                case -1:

                    if (comment.Name != userWhichUpvoted)
                    {
                        comment.Likes++;
                        comment.Dislikes--;

                        // register Turn DownVote To UpVote
                        var votingTracker = db.Commentvotingtrackers.FirstOrDefault(b => b.CommentId == commentId && b.UserName == userWhichUpvoted);

                        if (votingTracker != null)
                        {
                            votingTracker.VoteStatus = 1;
                            votingTracker.Timestamp  = DateTime.Now;
                        }
                        db.SaveChanges();

                        SendVoteNotification(comment.Name, "downtoupvote");
                    }

                    break;

                // upvoted before, reset
                case 1:

                    comment.Likes--;
                    db.SaveChanges();

                    SendVoteNotification(comment.Name, "downvote");

                    ResetCommentVote(userWhichUpvoted, commentId);

                    break;
                }
            }
        }
コード例 #5
0
ファイル: VotingComments.cs プロジェクト: Freem-/whoaverse
        //submit submission downvote
        public static void DownvoteComment(int commentId, string userWhichDownvoted)
        {
            int result = VotingComments.CheckIfVotedComment(userWhichDownvoted, commentId);

            using (whoaverseEntities db = new whoaverseEntities())
            {
                Comment comment = db.Comments.Find(commentId);

                switch (result)
                {
                //never voted before
                case 0:

                    if (comment != null)
                    {
                        comment.Dislikes++;

                        //register downvote
                        Commentvotingtracker tmpVotingTracker = new Commentvotingtracker();
                        tmpVotingTracker.CommentId  = commentId;
                        tmpVotingTracker.UserName   = userWhichDownvoted;
                        tmpVotingTracker.VoteStatus = -1;
                        db.Commentvotingtrackers.Add(tmpVotingTracker);
                        db.SaveChanges();
                    }

                    break;

                //upvoted before, turn upvote to downvote
                case 1:

                    if (comment != null)
                    {
                        comment.Likes--;
                        comment.Dislikes++;

                        //register Turn DownVote To UpVote
                        var votingTracker = db.Commentvotingtrackers
                                            .Where(b => b.CommentId == commentId && b.UserName == userWhichDownvoted)
                                            .FirstOrDefault();

                        if (votingTracker != null)
                        {
                            votingTracker.VoteStatus = -1;
                        }
                        db.SaveChanges();
                    }

                    break;

                //downvoted before, reset
                case -1:

                    if (comment != null)
                    {
                        comment.Dislikes--;
                        db.SaveChanges();
                        ResetCommentVote(userWhichDownvoted, commentId);
                    }

                    break;
                }
            }
        }