protected void AddComments()
        {
            if (submissionID != 0) {
                CommentManagementBO bo = new CommentManagementBO();
                List<CommentVO> commentList = bo.GetListOfSubmissionComments(submissionID);
                commentList = bo.SortComments(commentList);

                CommentVO previousComment = new CommentVO();
                Stack<int> pcStack = new Stack<int>();
                int depth = 0;

                foreach (CommentVO comment in commentList) {
                    //This determines the depth of the comment
                    //We only want to be indenting once, not every postback
                    if (!Page.IsPostBack) {
                        if (comment.ParentCommentID == 0) {
                            pcStack.Push(comment.CommentID);
                            depth = 0;
                        }
                        else if (comment.ParentCommentID == pcStack.Peek()) {
                            if (comment.ParentCommentID == previousComment.CommentID) {
                                pcStack.Push(comment.CommentID);
                                depth++;
                            }
                        }
                        else {
                            pcStack.Pop();
                            depth--;
                        }
                    }

                    Comment com = (Comment)Page.LoadControl("~/Controls/Comment.ascx");
                    com.ID = "comment" + comment.CommentID;
                    com.commentDepth = depth;
                    com.commentID = comment.CommentID;

                    commentPanel.Controls.Add(com);

                    previousComment = comment;
                }
            }
            else if (userID != 0) {
                CommentManagementBO bo = new CommentManagementBO();
                List<CommentVO> commentList = bo.GetListOfCommentsByUserID(userID, 5);

                foreach (CommentVO comment in commentList) {

                    Comment com = (Comment)Page.LoadControl("~/Controls/Comment.ascx");
                    com.ID = "comment" + comment.CommentID;
                    com.commentID = comment.CommentID;

                    commentPanel.Controls.Add(com);
                }
            }
        }
Beispiel #2
0
        protected void GenerateSubmissionDetails()
        {
            CommentManagementBO comBO = new CommentManagementBO();
            SubmissionManagementBO bo = new SubmissionManagementBO();
            SubmissionVO sub = bo.GetSubmission(submissionID);
            UserManagementBO userBO = new UserManagementBO();
            UserVO vo = userBO.GetUser(sub.UserID);

            submissionRating.Text = sub.Rating.ToString();
            submissionCommentLink.Text = (comBO.GetListOfSubmissionComments(submissionID).Count + " comments");

            Uri url;
            try {
                url = new Uri(sub.Link);
            }
            catch (Exception e) {
                try {
                    url = new Uri("http://" + sub.Link);
                }
                catch (Exception exc) {
                    url = new Uri("http://CouldntParseUrl");
                }
            }

            submissionTitle.Text = "<a href=\"" + url + "\">" + sub.Title + "</a> (" + url.Host.ToString() + ")";

            submissionDetails.Text = bo.FormatePostTime(sub.PostTime);

            userLink.Text = vo.Username;

            //Change arrow based on voting
            if(Session["login"] != null){
                int i = userBO.CheckIfVoted(submissionID, userBO.GetUser(Session["login"].ToString()).UserID);
                if (i == 1) {
                    upArrow.ImageUrl = "~/Images/uparrow_voted.png";
                }
                else if (i == -1) {
                    downArrow.ImageUrl = "~/Images/downarrow_voted.png";
                }
            }
        }