public void SetUp() { for (int i = 0; i < pcIDs.Length; i++) { CommentVO vo = new CommentVO(); vo.Rating = ratings[i]; vo.ParentCommentID = pcIDs[i]; list.Add(vo); } }
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); } } }
public void LoadInitialText(CommentVO vo) { string text = vo.CommentContents; text = text.Replace("<br/>", Environment.NewLine); text = text.Replace("<", "<"); text = text.Replace("&", "&"); text = text.Replace(""", "\""); text = text.Replace(">", ">"); text = text.Replace("<p>", ""); text = text.Replace("</p>", ""); editTextBox.Text = text; //A stupid little hack I'm having to put in, because my properties keep getting reset to null commentID.Text = vo.CommentID.ToString(); }
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"; } } }
public void CreateNewComment(string username, string commentContents, int subID, int pcID) { CommentDAO dao = new CommentDAO(); UserDAO userDAO = new UserDAO(); CommentVO comment = new CommentVO(); if (commentContents == null) { throw new Exception("You need to enter a comment"); } comment.UserID = userDAO.GetUser(username).UserID; comment.CommentContents = commentContents; comment.PostDate = DateTime.Now; comment.Rating = 0; if (pcID != 0) { comment.ParentCommentID = pcID; } comment.SubmissionID = subID; dao.InsertComment(comment); }
private List<CommentVO> GetCommentList(DbCommand command) { List<CommentVO> comList = new List<CommentVO>(); IDataReader reader = null; try { reader = Database.ExecuteReader(command); LogDebug("DataReader created, retrieving requested comment VO's..."); while (reader.Read()) { CommentVO com = new CommentVO(); com.CommentID = reader.GetInt32(0); com.CommentContents = reader.GetString(1); com.PostDate = reader.GetDateTime(2); com.Rating = reader.GetInt32(3); com.SubmissionID = reader.GetInt32(4); com.UserID = reader.GetInt32(5); com.ParentCommentID = reader.GetInt32(6); comList.Add(com); } LogDebug("List created!"); } catch (Exception e) { LogError("Something exploded in trying to retrieve a comment VO!", e); throw new Exception("Something exploded in trying to retrieve a comment VO!", e); } finally { base.CloseReader(reader); } return comList; }
private CommentVO FillInCommentVO(ref IDataReader reader) { CommentVO com = new CommentVO(); com.CommentID = reader.GetInt32(0); com.CommentContents = reader.GetString(1); com.PostDate = reader.GetDateTime(2); com.Rating = reader.GetInt32(3); com.SubmissionID = reader.GetInt32(4); com.UserID = reader.GetInt32(5); com.ParentCommentID = reader.GetInt32(6); return com; }
public void UpdateComment(CommentVO com) { DbCommand command = Database.GetSqlStringCommand(UPDATE_COMMENT); try { Database.AddInParameter(command, COMMENT_CONTENTS, DbType.String, com.CommentContents); Database.AddInParameter(command, POST_DATE, DbType.DateTime, com.PostDate); Database.AddInParameter(command, RATING, DbType.Int32, com.Rating); Database.AddInParameter(command, SUBMISSION_ID, DbType.Int32, com.SubmissionID); Database.AddInParameter(command, USER_ID, DbType.Int32, com.UserID); Database.AddInParameter(command, PARENT_COMMENT_ID, DbType.Int32, com.ParentCommentID); Database.AddInParameter(command, COMMENT_ID, DbType.Int32, com.CommentID); Database.ExecuteScalar(command); } catch (Exception e) { LogError("Something exploded while updating comment " + com.CommentID); throw new Exception("Something exploded while updating comment " + com.CommentID); } }
public CommentVO InsertComment(CommentVO com) { int cID = 0; try { DbCommand command = Database.GetSqlStringCommand(INSERT_COMMENT); Database.AddInParameter(command, COMMENT_CONTENTS, DbType.String, com.CommentContents); Database.AddInParameter(command, POST_DATE, DbType.DateTime, com.PostDate); Database.AddInParameter(command, RATING, DbType.Int32, com.Rating); Database.AddInParameter(command, SUBMISSION_ID, DbType.Int32, com.SubmissionID); Database.AddInParameter(command, USER_ID, DbType.Int32, com.UserID); Database.AddInParameter(command, PARENT_COMMENT_ID, DbType.Int32, com.ParentCommentID); cID = Convert.ToInt32(Database.ExecuteScalar(command)); } catch (Exception e) { LogError("Something exploded while trying to insert a comment!", e); throw new Exception("Something exploded while trying to insert a comment!", e); } return GetComment(cID); }
public void DeleteComment(CommentVO com) { int rowsAffected = 0; try { DeleteComment(com.CommentID); } catch (Exception e) { LogError("Something exploded while deleting a comment from the database!", e); throw new Exception("Something exploded while deleting a comment from the database!", e); } if (rowsAffected == 0) { LogError("No comment found with an ID of " + com.CommentID); throw new Exception("The delete command didn't delete anything!"); } }
public void UpdateComment(CommentVO comment) { CommentDAO dao = new CommentDAO(); dao.UpdateComment(comment); }