private void Edit() { Post postToEdit = Choose("Which post would you like to edit?"); if (postToEdit == null) { return; } Console.WriteLine(); Console.Write("New title (blank to leave unchanged: "); string title = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(title)) { postToEdit.Title = title; } Console.Write("New URL (blank to leave unchanged: "); string url = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(url)) { postToEdit.Url = url; } AuthorManager authorManager = new AuthorManager(this, _connectionString); AuthorRepository authRepo = new AuthorRepository(_connectionString); Author newAuthor = authorManager.Choose(); if (newAuthor != null) { postToEdit.Author = newAuthor; } else { postToEdit.Author = authRepo.Get(postToEdit.Author.Id); } BlogManager blogManager = new BlogManager(this, _connectionString); BlogRepository blogRepo = new BlogRepository(_connectionString); Blog newBlog = blogManager.Choose(); if (newBlog != null) { postToEdit.Blog = newBlog; } else { postToEdit.Blog = blogRepo.Get(postToEdit.Blog.Id); } _postRepository.Update(postToEdit); }
// Define an Add method to engage the user in adding a Post Object to the database private void Add() { Console.WriteLine("New Post"); Post post = new Post(); Console.Write("Title: "); post.Title = Console.ReadLine(); Console.Write("Url: "); post.Url = Console.ReadLine(); Console.Write("Published Date (e.g. 1/12/2014): "); post.PublishDateTime = DateTime.Parse(Console.ReadLine()); // Use the Choose() method that is predefined in the AuthorManager post.Author = _authorManager.Choose("Author: "); // Use the Choose() method that is predefined in the BlogManager post.Blog = _blogManager.Choose("Blog: "); _postRepository.Insert(post); }
private void Add() { AuthorRepository authRepo = new AuthorRepository(_connectionString); Console.WriteLine("New Post"); Post post = new Post(); Console.Write("Title: "); post.Title = Console.ReadLine(); Console.Write("URL: "); post.Url = Console.ReadLine(); Console.Write("Publish Date: "); post.PublishDateTime = DateTime.Parse(Console.ReadLine()); AuthorManager authorManager = new AuthorManager(this, _connectionString); post.Author = authorManager.Choose(); BlogManager blogManager = new BlogManager(this, _connectionString); post.Blog = blogManager.Choose(); _postRepository.Insert(post); }