コード例 #1
0
        static void Main(string[] args)
        {
            // In a real world example the string below would be pulled from the inputfield of course...
            Console.WriteLine("Title..:");
            var title = Console.ReadLine();

            Console.WriteLine("Post..:");
            var post = new Post(title, Console.ReadLine());

            // 7 Upvotes...
            for (int i = 1; i <= 7; i++)
            {
                post.Upvote();
            }

            // And 3 Downvotes...
            for (int i = 1; i <= 3; i++)
            {
                post.DownVote();
            }

            Console.WriteLine("Post | ({0}) | \"{1}\" [score: {2}]", post.PostTitle, post.PostContent, post.PostScore);
            Console.ReadKey(true);

            // Here comes reddit! 300 downvotes...
            for (int i = 1; i <= 300; i++)
            {
                post.DownVote();
            }

            // Udemy to the rescue (500 votes!)...
            for (int i = 1; i <= 500; i++)
            {
                post.Upvote();
            }

            Console.WriteLine("Post | ({0}) | \"{1}\" [score: {2}]", post.PostTitle, post.PostContent, post.PostScore);
            Console.ReadKey(true);

            // In the real world there would be an input field for the user to edit the post. We assume this method
            // Would then take the new version of the post and insert it as a new string.
            // Note that this OP is not a nice human as he didn't post the fix!!!
            post.EditPost("Solved - Please close", "Edit: I fixed this now please close the post...");

            Console.WriteLine("Post | ({0}) | \"{1}\" [score: {2}]", post.PostTitle, post.PostContent, post.PostScore);
            Console.ReadKey(true);

            // Downvoted to oblivion for bad internet manners.
            for (int i = 1; i <= 4124; i++)
            {
                post.DownVote();
            }

            Console.WriteLine("Post | ({0}) | \"{1}\" [score: {2}]", post.PostTitle, post.PostContent, post.PostScore);
            Console.ReadKey(true);
        }
コード例 #2
0
ファイル: Menu.cs プロジェクト: etkachev/stackoverflowPost
        public void RunMenu()
        {
            while (_menuRunning)
            {
                Console.WriteLine("Select from the following:\n" +
                              "1. View Posts\n" +
                              "2. Create Post\n" +
                              "3. Quit");
                _input = Console.ReadLine();
                Console.Clear();

                if (_input == "1")
                {
                    if (Posts.Count == 0)
                    {
                        Console.WriteLine("No posts yet.");
                        Console.ReadLine();
                        Console.Clear();
                    }
                    else
                    {
                        foreach (Post p in Posts)
                        {
                            Console.WriteLine("{0}.", _postNumber);
                            p.ShowPost();
                            _postNumber++;
                        }

                        Console.WriteLine("Select the Post you would like to Upvote or DownVote\n(Select the number of the Post)...");
                        if (Int32.TryParse(Console.ReadLine(), out _postSelect))
                        {
                            for (int i = 0; i < _postNumber-1; i++)
                            {
                                if (_postSelect-1 == i)
                                {
                                    Console.Clear();
                                    var p2 = Posts.ElementAt(i);
                                    p2.ShowPost();
                                    Console.WriteLine("\nSelect (1) to Upvote\nSelect (2) to Downvote");
                                    _vote = Console.ReadLine();
                                    if (_vote == "1")
                                    {
                                        p2.UpVote();
                                    }
                                    else if (_vote == "2")
                                    {
                                        p2.DownVote();
                                    }
                                }
                                else if (_postSelect >= _postNumber)
                                {
                                    Console.WriteLine("There is no such post");
                                    Console.ReadLine();
                                    break;
                                }
                            }

                            _postNumber = 1;
                            Console.Clear();
                        }
                        else
                        {
                            _postNumber = 1;
                            Console.Clear();
                        }

                    }

                }
                else if (_input == "2")
                {
                    Post newPost = new Post();
                    Console.WriteLine("Please provide title first: ");
                    _titleInput = Console.ReadLine();
                    newPost.Title = _titleInput;
                    Console.Clear();
                    Console.WriteLine("Now provide a description:");
                    _descInput = Console.ReadLine();
                    newPost.Description = _descInput;
                    Posts.Add(newPost);
                    Console.Clear();
                }
                else if (_input == "3")
                {
                    _menuRunning = false;
                }
            }

            Console.WriteLine("Thank you for using StackOverflow. Come again!");
            Console.ReadLine();
        }