public static void AddPost() //Adds post object to list { List <Post> allPosts = FileControl.PostList; Guid g = Guid.NewGuid(); string id = g.ToString(); string text = ""; DateTime currTime = DateTime.Now; Console.Write("Enter Post Message: "); text = Console.ReadLine(); Console.Clear(); allPosts.Add(new Post() { ID = id, PostText = text, Date = currTime.ToString() }); allPosts.Sort(); allPosts.Reverse(); FileControl.PostList = allPosts; FileControl.Save(); Console.WriteLine("Post created successfully.\nPress any key to continue..."); Console.ReadKey(); Console.Clear(); }
static void Main(string[] args) //Flow of control { FileControl.Clone(); String input = ""; while (input.CompareTo("4") != 0) { PrintMenuOptions(); ValidateMenuChoice(ref input); } }
public static void DeletePost() //deletes post object from list { List <Post> allPosts = FileControl.PostList; int count = 1; Console.WriteLine("All Posts\n---------"); foreach (Post post in allPosts) { Console.WriteLine("\t" + count + ". " + post.ToString()); count++; } string input = ""; Console.Write("\nPlease select item to delete (enter \"return\" to exit)): "); input = Console.ReadLine(); Console.Clear(); if (input.ToLower().Equals("return")) { return; } try{ int value = int.Parse(input) - 1; allPosts.RemoveAt(value); allPosts.Sort(); allPosts.Reverse(); FileControl.PostList = allPosts; FileControl.Save(); Console.WriteLine("Post removed successfully.\nPress any key to continue..."); Console.ReadKey(); Console.Clear(); } catch (Exception e) { Console.WriteLine("ERROR: Post cannot be deleted."); Console.WriteLine(e.Message); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } }