예제 #1
0
        static void Main(string[] args)
        {
            List <Post> tweet = PostFile.GetPosts();

            Console.WriteLine("Welcome to Big Al's Post");
            Menu();
        }
예제 #2
0
        static void Menu()
        {
            List <Post> tweet = PostFile.GetPosts();
            bool        exit  = false;


            while (exit == false)
            {
                //Menu selections
                Console.WriteLine("Please Select: \n" +
                                  "[1] Show all Post \n" +
                                  "[2] Add Post \n" +
                                  "[3] Delete Post by ID\n" +
                                  "[4] Exit \n");
                string userSelection = Console.ReadLine();
                int    selection     = 0;

                //Error checking loop that only accepts numbers
                bool valid = int.TryParse(userSelection, out selection);
                while ((valid == false) || (!(selection == 1 || selection == 2 || selection == 3 || selection == 4)))
                {
                    Console.WriteLine("Error Please enter a valid selection");

                    userSelection = Console.ReadLine();
                    valid         = int.TryParse(userSelection, out selection);
                }

                //Menu logic options
                if (selection == 1)
                {
                    Console.WriteLine("Show All Post");
                    Post.ShowAllPost(tweet);
                }
                else if (selection == 2)
                {
                    Console.WriteLine("Add Post");
                    Post.AddPost(tweet);
                }
                else if (selection == 3)
                {
                    Console.WriteLine("Delete Post");
                    Post.DeletePost(tweet);
                }
                else if (selection == 4)
                {
                    exit = true;
                    Console.WriteLine("Thank you. Have a nice day!");
                }
            }
        }
예제 #3
0
        public static void AddPost(List <Post> tweet)
        {
            Console.WriteLine("");
            Console.WriteLine("Please enter your tweet");
            Console.WriteLine("");

            string userTweet = Console.ReadLine();

            tweet.Add(new Post()
            {
                PostID = Guid.NewGuid(), PostMessage = userTweet, Time = DateTime.Now
            });

            ReverseSort(tweet);
            PostFile.SavePost(tweet);
        }
예제 #4
0
        public static void DeletePost(List <Post> tweet)
        {
            ShowAllPost(tweet);
            Console.WriteLine("Please enter the Post Id you would like to delete");

            string temp = Console.ReadLine();
            Guid   selection;

            bool valid = Guid.TryParse(temp, out selection);

            while (valid == false)
            {
                Console.WriteLine("");
                Console.WriteLine("Error Please enter a valid Post ID");
                Console.WriteLine("");

                temp  = Console.ReadLine();
                valid = Guid.TryParse(temp, out selection);
            }


            int index = tweet.FindIndex(x => x.PostID == selection);

            if (index != -1)
            {
                tweet.RemoveAt(index);
            }
            else
            {
                Console.WriteLine("");
                Console.WriteLine("Could not find Post ID");
                Console.WriteLine("");
            }


            ReverseSort(tweet);
            PostFile.SavePost(tweet);
        }