Save() public method

public Save ( Post entity ) : int
entity Post
return int
        private int CreatePost(string title, string text, DateTime published)
        {
            IPostRepository repo = new PostRepository(new BlogContext());

            var post = new Post
                           {
                               Title = title,
                               Text = text,
                               PublishDate = published
                           };

            return repo.Save(post);
        }
Example #2
0
        private int CreatePost(string title, string text, DateTime published, params Comment[] comments)
        {
            IPostRepository repo = new PostRepository(new BlogContext());

            var post = new Post
                           {
                               Title = title,
                               Text = text,
                               PublishDate = published
                           };

            post.Comments = new Collection<Comment>();

            foreach(var comment in comments)
            {
                post.Comments.Add(new Comment() { Text = comment.Text, Author = comment.Author});
            }

            return repo.Save(post);
        }