Пример #1
0
        //submit submission downvote
        public static void DownvoteSubmission(int submissionId, string userWhichDownvoted)
        {
            int result = Voting.CheckIfVoted(userWhichDownvoted, submissionId);

            using (whoaverseEntities db = new whoaverseEntities())
            {
                Message submission = db.Messages.Find(submissionId);

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

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

                            double currentScore = submission.Likes - submission.Dislikes;
                            double submissionAge = Whoaverse.Utils.Submissions.CalcSubmissionAgeDouble(submission.Date);
                            double newRank = Ranking.CalculateNewRank(submission.Rank, submissionAge, currentScore);

                            submission.Rank = newRank;

                            //register downvote
                            Votingtracker tmpVotingTracker = new Votingtracker();
                            tmpVotingTracker.MessageId = submissionId;
                            tmpVotingTracker.UserName = userWhichDownvoted;
                            tmpVotingTracker.VoteStatus = -1;
                            db.Votingtrackers.Add(tmpVotingTracker);
                            db.SaveChanges();
                        }

                        break;

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

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

                            double currentScore = submission.Likes - submission.Dislikes;
                            double submissionAge = Whoaverse.Utils.Submissions.CalcSubmissionAgeDouble(submission.Date);
                            double newRank = Ranking.CalculateNewRank(submission.Rank, submissionAge, currentScore);

                            submission.Rank = newRank;

                            //register Turn DownVote To UpVote
                            var votingTracker = db.Votingtrackers
                                .Where(b => b.MessageId == submissionId && b.UserName == userWhichDownvoted)
                                .FirstOrDefault();

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

                        break;

                    //downvoted before, reset
                    case -1:

                        if (submission != null)
                        {
                            submission.Dislikes--;

                            double currentScore = submission.Likes - submission.Dislikes;
                            double submissionAge = Whoaverse.Utils.Submissions.CalcSubmissionAgeDouble(submission.Date);
                            double newRank = Ranking.CalculateNewRank(submission.Rank, submissionAge, currentScore);

                            submission.Rank = newRank;
                            db.SaveChanges();

                            ResetMessageVote(userWhichDownvoted, submissionId);
                        }

                        break;

                }
            }
        }
Пример #2
0
        //a user has either upvoted or downvoted this submission earlier and wishes to reset the vote, delete the record
        public static void ResetMessageVote(string userWhichVoted, int messageId)
        {
            using (whoaverseEntities db = new whoaverseEntities())
            {
                var votingTracker = db.Votingtrackers
                                .Where(b => b.MessageId == messageId && b.UserName == userWhichVoted)
                                .FirstOrDefault();

                if (votingTracker != null)
                {
                    //delete vote history
                    db.Votingtrackers.Remove(votingTracker);
                    db.SaveChanges();
                }
            }
        }
Пример #3
0
        // unsubscribe from a subverse
        public static void UnSubscribeFromSubverse(string userName, string subverse)
        {
            if (IsUserSubverseSubscriber(userName, subverse))
            {
                using (whoaverseEntities db = new whoaverseEntities())
                {
                    var subscription = db.Subscriptions
                                .Where(b => b.Username == userName && b.SubverseName == subverse)
                                .FirstOrDefault();

                    if (subverse != null)
                    {
                        // remove subscription record
                        db.Subscriptions.Remove(subscription);

                        // record new unsubscription in subverse table subscribers field
                        Subverse tmpSubverse = db.Subverses.Find(subverse);

                        if (tmpSubverse != null)
                        {
                            tmpSubverse.subscribers--;
                        }

                        db.SaveChanges();
                    }

                }
            }
        }
Пример #4
0
        //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;
                }
            }
        }
Пример #5
0
        // subscribe to a subverse
        public static void SubscribeToSubverse(string userName, string subverse)
        {
            if (!IsUserSubverseSubscriber(userName, subverse))
            {
                using (whoaverseEntities db = new whoaverseEntities())
                {
                    // add a new subscription
                    Subscription newSubscription = new Subscription();
                    newSubscription.Username = userName;
                    newSubscription.SubverseName = subverse;
                    db.Subscriptions.Add(newSubscription);

                    // record new subscription in subverse table subscribers field
                    Subverse tmpSubverse = db.Subverses.Find(subverse);

                    if (tmpSubverse != null)
                    {
                        tmpSubverse.subscribers++;
                    }

                    db.SaveChanges();
                }
            }
        }