public ActionResult AddComment(CommentDto NewComment)
 {
     var success = BlogQueries.CreateComment(NewComment);
        if (success)
        TempData["Message"] = "Your comment was successfully posted";
        return RedirectToAction("View", new { id = NewComment.PostId });
 }
        public static bool CreateComment(CommentDto comment)
        {
            var rowsAffected = 0;
            using (var conn = Connection.GetConnection())
            {
                conn.Open();
                var createCommand = "INSERT INTO Comments (PostId,Message,CreatedOn,CreatedBy) VALUES ("
                                    + comment.PostId + ", '"
                                    + comment.Message + "', '"
                                    + DateTime.Now.ToString("M/d/yyyy hh:mm:ss tt") + "', '"
                                    + comment.CreatedBy + "');"
                                    + " UPDATE Posts SET CommentsCount = CommentsCount + 1 WHERE PostId = " + comment.PostId;

                using (var cmd = new SqlCommand(createCommand, conn))
                {
                    cmd.CommandType = CommandType.Text;
                    rowsAffected = cmd.ExecuteNonQuery();
                }
                conn.Close();
            }
            return rowsAffected > 0;
        }
 private static CommentDto ReadComment(SqlDataReader dr)
 {
     var c = new CommentDto
                 {
                     CommentId   = Convert.ToInt32(dr["CommentId"]),
                     Message     = dr["Message"] != DBNull.Value ? dr["Message"].ToString() : string.Empty,
                     CreatedBy   = dr["CreatedBy"] != DBNull.Value ? dr["CreatedBy"].ToString() : string.Empty,
                     CreatedOn   = dr["CreatedOn"] != DBNull.Value ? Convert.ToDateTime(dr["CreatedOn"].ToString()) : DateTime.MinValue
                 };
     return c;
 }
 public BlogPostModel()
 {
     Post = new PostDto();
     Comments = new List<CommentDto>();
     NewComment = new CommentDto();
 }