public void CommentOnPost(Post post, string commentAuthor, string commentText)
        {
            var comment = new Comment {Author = commentAuthor, Text = commentText, PostedDate = DateTime.Now};
            post.AddComment(comment);

            commentRepository.Create(comment);
            postRepository.Update(post);

            postLogger.LogMessage("Created comment from '{0}' on post '{1}'",
                                  comment.Author, post.Title);
        }
Example #2
0
        private static void CreatePost(string title)
        {
            var postRepository = new PostRepository();
            var categoryRepository = new CategoryRepository();
            var commentRepository = new CommentRepository();

            var post = new Post
                           {
                               Title = title,
                               PostedDate = DateTime.Now,
                               Contents = "This is just a simple test post..."
                           };

            for (int i = 0; i < 10; i++)
            {
                var category = new Category
                                   {
                                       Name = "Category " + i,
                                       CreatedDate = DateTime.Now,
                                       Description = "Just a test..."
                                   };

                post.AddCategory(category);
                categoryRepository.Create(category);
            }

            for (int i = 0; i < 20; i++)
            {
                var comment = new Comment
                                  {
                                      PostedDate = DateTime.Now,
                                      Author = "Author " + i,
                                      Text = "testing..."
                                  };

                post.AddComment(comment);
                commentRepository.Create(comment);
            }

            postRepository.Create(post);
        }