Пример #1
0
        public static bool TakeBackUpvoteProblem(ForumPost forumPost)
        {
            error.Clear();
            if (!CurrentUser.isLoggedIn)
            {
                return(error.SetErrorAndReturnFalse(ErrorCode.INVALID_SESSION));
            }
            if (!DataCrusher.TakeBackUpvoteForForum(forumPost))
            {
                return(error.SetErrorAndReturnFalse(ErrorCode.NOT_FOUND));
            }
            //previous votes
            int votes = DataFetcher.GetForumPostVotes(forumPost);

            votes -= 1;
            if (!DataPusher.SetForumPostVotes(forumPost, votes))
            {
                return(error.SetErrorAndReturnFalse(ErrorCode.PUSH_ERROR));
            }
            return(true);
        }
Пример #2
0
        public static bool UpvoteProblem(ForumPost forumPost)
        {
            error.Clear();
            if (CurrentUser.isLoggedIn == false)
            {
                return(error.SetErrorAndReturnFalse(ErrorCode.INVALID_SESSION));
            }
            bool upVoted = false; //so far

            try
            {
                upVoted = UserDataPusher.UpvoteForumProblem(forumPost); //exception root
                if (!upVoted)
                {
                    return(error.SetErrorAndReturnFalse(ErrorCode.PUSH_ERROR | ErrorCode.UNKNOWN));
                }
                //upvoted
                //previous votes number
                int votes = DataFetcher.GetForumPostVotes(forumPost);
                //set votes to previous+1
                votes += 1;
                if (!DataPusher.SetForumPostVotes(forumPost, votes))
                {
                    return(error.SetErrorAndReturnFalse(ErrorCode.PUSH_ERROR));
                }
                return(true);
            }
            catch (MySql.Data.MySqlClient.MySqlException myEx)
            { //^exception handling
                if (myEx.Number == (uint)MySql.Data.MySqlClient.MySqlErrorCode.DuplicateKeyEntry)
                {
                    throw new exceptions.DoneBefore();
                }
                else
                {
                    throw myEx;
                }
            }
        }