示例#1
0
        public static List<Comment> FindCommentsByItemID(string itemID)
        {
            List<Comment> result = new List<Comment>();

            string connectionString = WebConfigurationManager.ConnectionStrings["defaultConnectionString"].ToString();
            SqlConnection sqlConn = new SqlConnection(connectionString);
            sqlConn.Open();

            string cmdString = "SELECT * FROM Comment WHERE ParentCommentID = 0 AND ItemID = @itemID ORDER BY ModifiedDate DESC";
            SqlCommand sqlCmd = new SqlCommand(cmdString, sqlConn);
            sqlCmd.Parameters.Add(new SqlParameter("itemID", itemID));

            SqlDataReader sqlDataReader = sqlCmd.ExecuteReader();
            if (sqlDataReader.HasRows)
            {
                while (sqlDataReader.Read())
                {
                    Comment newComment = new Comment();
                    FillComment(sqlDataReader, newComment);
                    newComment.childComments = GetChildComments(newComment.CommentID);
                    result.Add(newComment);
                }
                sqlDataReader.Close();
            }

            return result;
        }
示例#2
0
 static void FillComment(SqlDataReader sqlDataReader, Comment newComment)
 {
     newComment.CommentID = (int)sqlDataReader["CommentID"];
     newComment.ParentCommentID = (int)sqlDataReader["ParentCommentID"];
     newComment.ItemID = (string)sqlDataReader["ItemID"];
     newComment.UserID = (int)sqlDataReader["UserID"];
     newComment.Text = (string)sqlDataReader["Text"];
     newComment.ModifiedDate = (DateTime)sqlDataReader["ModifiedDate"];
 }
示例#3
0
        public static void AddComment(Comment newComment)
        {
            string connectionString = WebConfigurationManager.ConnectionStrings["defaultConnectionString"].ToString();
            SqlConnection sqlConn = new SqlConnection(connectionString);
            sqlConn.Open();

            string cmdString = "INSERT INTO [Comment] (ParentCommentID, ItemID, UserID, Text, ModifiedDate) VALUES (@parentCommentID, @itemID, @userID, @text, @modifiedDate)";
            SqlCommand sqlCmd = new SqlCommand(cmdString, sqlConn);
            sqlCmd.Parameters.Add(new SqlParameter("parentCommentID", newComment.ParentCommentID));
            sqlCmd.Parameters.Add(new SqlParameter("itemID", newComment.ItemID));
            sqlCmd.Parameters.Add(new SqlParameter("userID", newComment.UserID));
            sqlCmd.Parameters.Add(new SqlParameter("text", newComment.Text));
            sqlCmd.Parameters.Add(new SqlParameter("modifiedDate", newComment.ModifiedDate));

            sqlCmd.ExecuteNonQuery();

            sqlConn.Close();
        }
示例#4
0
 public static void AddComment(Comment newItem)
 {
     newItem.Text = HttpUtility.HtmlEncode(newItem.Text);
     CommentRepository.AddComment(newItem);
 }
示例#5
0
 protected void ButtonCommitComment_Click(object sender, EventArgs e)
 {
     if (AuthenticationService.GetUsername() == null)
     {
         Response.Redirect(@"~\Account\Login.aspx");
         return;
     }
     Comment newComment = new Comment();
     newComment.ParentCommentID = 0;
     newComment.UserID = AuthenticationService.GetUser().UserID;
     newComment.ItemID = itemID;
     newComment.ModifiedDate = DateTime.Now;
     newComment.Text = TextBoxComment.Text;
     CommentService.AddComment(newComment);
     Response.Redirect(Request.Url.ToString());
 }