public void Test() { CommentManagementBO bo = new CommentManagementBO(); bo.SortComments(list); foreach (CommentVO com in list) { System.Diagnostics.Debug.WriteLine(com.CommentID + " " + com.ParentCommentID + " " + com.Rating); } }
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); } } }
protected void LoadCommentDetails() { CommentManagementBO bo = new CommentManagementBO(); UserManagementBO userBO = new UserManagementBO(); CommentVO vo = bo.GetComment(commentID); comVO = vo; //Give comment space for its depth for (int i = 0; i < commentDepth; i++) { spacingLabel.Text = spacingLabel.Text + "<td width=\"25px\"></td>"; } commentRating = vo.Rating; string username = userBO.GetUser(vo.UserID).Username; userLink.Text = username; commentInfo.Text = " rated at " + commentRating + " points, posted " + bo.FormatePostTime(vo.PostDate); commentContents.Text = "<p>" + vo.CommentContents + "</p>"; //Choose which controls to display if(Session["login"] == null){ editButton.Visible = false; deleteButton.Visible = false; replyButton.Visible = false; } else if (!username.Equals(Session["login"].ToString())) { editButton.Visible = false; deleteButton.Visible = false; } //Change vote image based on whether or not it's been voted on if(Session["login"] != null){ int i = bo.CheckIfVoted(commentID, 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"; } } }
protected void SubmitReply_Click(object sender, EventArgs e) { CommentManagementBO bo = new CommentManagementBO(); UserManagementBO userBO = new UserManagementBO(); try { if (replyTextBox.Text == "") { throw new Exception("You must enter text to reply"); } bo.CreateNewComment(userBO.GetUser(Session["login"].ToString()).Username, replyTextBox.Text, Convert.ToInt32(Request.QueryString["subid"]), Convert.ToInt32(parentCommentID.Text)); Response.Redirect(Request.Url.ToString()); } catch (Exception exc) { errorLabel.Text = exc.Message; } }
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"; } } }
protected void SubmitButton_Click(object sender, EventArgs e) { CommentManagementBO bo = new CommentManagementBO(); try { if (Session["login"] == null) { throw new Exception("You must be logged in to comment!"); } else if (commentContents.Text.Equals("")) { throw new Exception("A comment must be entered"); } string comText = commentContents.Text; comText = Server.HtmlEncode(comText); comText = comText.Replace(Environment.NewLine, "<br/>"); bo.CreateNewComment(Session["login"].ToString(), comText, submissionID, parentCommentID); Response.Redirect(WebConstants.SUBMISSION_COMMENT_PAGE + "?subid=" + submissionID); } catch (Exception exc) { errorLabel.Text = exc.Message; } }
protected void SubmitEdit_Click(object sender, EventArgs e) { CommentManagementBO bo = new CommentManagementBO(); //A stupid little hack I'm having to put in, because my properties keep getting reset to null CommentVO commentVO = bo.GetComment(Convert.ToInt32(commentID.Text)); try { //Check for no text if (editTextBox.Text.Equals("")) { throw new Exception(NO_TEXT_EXCEPTION); } //Edit comment string comText = editTextBox.Text; comText = Server.HtmlEncode(comText); comText = comText.Replace(Environment.NewLine, "<br/>"); commentVO.CommentContents = comText; bo.UpdateComment(commentVO); this.Visible = false; Response.Redirect(Request.Url.ToString()); } catch (Exception exc) { errorLabel.Text = exc.Message; } }
private void GenerateRecentContent(string type) { if (type == "submissions") { //We need to add a table for submissions, since they are just trs and tds Literal lit1 = new Literal(); lit1.Text = "<table width=\"100%\">"; recentContentPanel.Controls.Add(lit1); SubmissionManagementBO bo = new SubmissionManagementBO(); List<SubmissionVO> subList = bo.GetListOfSubmissionsByUser(5, UserID); foreach (SubmissionVO sub in subList) { Submission submission = (Submission)Page.LoadControl("~/Controls/Submission.ascx"); submission.ID = "submission" + sub.SubmissionID; submission.submissionID = sub.SubmissionID; recentContentPanel.Controls.Add(submission); } //We need to close the table tag we added Literal lit2 = new Literal(); lit2.Text = "</table>"; recentContentPanel.Controls.Add(lit2); } else if(type == "comments") { CommentManagementBO bo = new CommentManagementBO(); List<CommentVO> comList = bo.GetListOfCommentsByUserID(5, UserID); foreach (CommentVO comment in comList) { Comment com = (Comment)Page.LoadControl("~/Controls/Comment.ascx"); com.ID = "comment" + comment.CommentID; com.commentDepth = 0; com.commentID = comment.CommentID; recentContentPanel.Controls.Add(com); } } }
protected void DeleteButton_Click(object sender, EventArgs e) { CommentManagementBO bo = new CommentManagementBO(); bo.DeleteComment(commentID); Response.Redirect(Request.Url.ToString()); }
protected void SubmitVote(int vote) { CommentManagementBO comBO = new CommentManagementBO(); UserManagementBO userBO = new UserManagementBO(); CommentVO comVO = comBO.GetComment(commentID); UserVO userVO; if (Session["login"] != null) { userVO = userBO.GetUser(Session["login"].ToString()); if (comBO.CheckIfVoted(commentID, userVO.UserID) == 0) { comBO.SubmitVote(commentID, userVO.UserID, vote); commentRating += vote; Response.Redirect(Request.Url.ToString()); } } }