private void Edit() { Post postToEdit = Choose("Which post would you like to edit?"); if (postToEdit == null) { return; } Console.WriteLine(); EditTitle: Console.Write("New title for the post (blank to leave unchanged): "); string title = Console.ReadLine(); if (title.Length > 55) { Console.WriteLine(); Console.WriteLine("Title was too long. Please Enter a title:"); goto EditTitle; } else if (!string.IsNullOrWhiteSpace(title)) { postToEdit.Title = title; } Console.Write("New URL for the post (blank to leave unchanged): "); EditUrl: string url = Console.ReadLine(); if (url.Length > 2000) { Console.WriteLine(); Console.WriteLine("Url was too long. Please Enter a url:"); goto EditUrl; } else if (!string.IsNullOrWhiteSpace(url)) { postToEdit.Url = url; } Console.Write("New publishing date for the post (blank to leave unchanged): "); string datePublished = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(datePublished)) { postToEdit.PublishDateTime = Convert.ToDateTime(datePublished);; } AuthorManager authorManager = new AuthorManager(this, _connectionString); postToEdit.Author = authorManager.ChooseAuthor(); BlogManager blogManager = new BlogManager(this, _connectionString); postToEdit.Blog = blogManager.ChooseBlog(); _postRepository.Update(postToEdit); }
private void Add() { Console.WriteLine("New Post"); Post post = new Post(); Console.Write("Title: "); Title: string title = Console.ReadLine(); if (string.IsNullOrWhiteSpace(title)) { Console.WriteLine(); Console.WriteLine("Please Enter a title:"); goto Title; } else if (title.Length > 55) { Console.WriteLine(); Console.WriteLine("Title was too long. Please Enter a title:"); goto Title; } post.Title = title; Console.Write("URL: "); Url: string url = Console.ReadLine(); if (string.IsNullOrWhiteSpace(url)) { Console.WriteLine(); Console.WriteLine("Please Enter a url:"); goto Url; } else if (url.Length > 2000) { Console.WriteLine(); Console.WriteLine("Url was too long. Please Enter a url:"); goto Url; } post.Url = url; bool badDate = true; while (badDate) { try { Console.Write("Date published: "); post.PublishDateTime = Convert.ToDateTime(Console.ReadLine()); badDate = false; } catch (Exception) { Console.WriteLine("Date not accepted, please try again"); } } AuthorManager authorManager = new AuthorManager(this, _connectionString); post.Author = authorManager.ChooseAuthor(); BlogManager blogManager = new BlogManager(this, _connectionString); post.Blog = blogManager.ChooseBlog(); _postRepository.Insert(post); }