コード例 #1
0
        private static void PostInterface(PostPoco post)
        {
            if (Account.Id == post.UserId)
            {
                Console.WriteLine("DISCLAIMER: You can edit this post!");
                Console.WriteLine("Type: edit help to see how to edit!");
            }

            Console.WriteLine("Type 'all comments' to see all comments on this post! (If any)");
            Console.WriteLine("Type 'my comments' to see your comments on this post! (If any)");
            Console.WriteLine("Type 'comment post' to comment on this post!");
            Console.WriteLine("Type 'return' to return to the blog!");
            Console.WriteLine("Type 'refresh' to view again this post!\n");

            while (true)
            {
                Console.Write("Blog -->#Post: ");
                string line = Console.ReadLine()?.Trim().ToLowerInvariant().Replace(" ", string.Empty);

                if (!string.IsNullOrEmpty(line))
                {
                    if (line == "return")
                    {
                        break;
                    }

                    switch (line)
                    {
                    case "clear":
                        Console.Clear();
                        break;

                    case "refresh":
                        Post.ViewPost(CurrentPost);
                        break;

                    case "commentpost":
                        CreateCommentInterface();
                        break;

                    case "mycomments":
                        ShowUserComments();
                        break;

                    case "allcomments":
                        Blog.AllComments(CurrentPost);
                        break;

                    case "delete":
                        Blog.DeleteProcess(post);
                        break;

                    case "edithelp":
                        CommandPrinter.ShowPostEdits();
                        break;

                    case "edittitle":
                        Console.Write("New title: ");
                        Post.EditPostTitle(CurrentPost, Console.ReadLine() ?? " ");
                        break;

                    case "editcontent":
                        EditPostContentInterface();
                        break;

                    default:
                        Console.WriteLine("Your command was invalid!");
                        break;
                    }
                }
            }
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: CloudNStoyan/blog
        static void Main()
        {
            Console.WriteLine("#==========================================================#");
            Console.WriteLine("#===========================BLOG===========================#");
            Console.WriteLine("#==========================================================#");

            using (var conn = new NpgsqlConnection(Blog.ConnectionString))
            {
                conn.Open();
                var database = new Database(conn);
                var service  = new Service(database);
                Console.WriteLine(service.UserExist("admin"));


                var allPosts = service.GetAllPosts();
                foreach (var post in allPosts)
                {
                    Console.WriteLine(post.Title);
                }
            }



            while (true)
            {
                Console.Write("Do you have an existing account! (Y/N) ");
                string line = Console.ReadLine() ?? " ";

                if (string.IsNullOrEmpty(line))
                {
                    Console.WriteLine("Thats not a valid answer use only 'Y' for yes and 'N' for no!");
                    continue;
                }

                if (line.ToLowerInvariant().Trim() == "n")
                {
                    Account.CreateInterface();
                    break;
                }
                else if (line.ToLowerInvariant().Trim() == "y")
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Thats not a valid answer use only 'Y' for yes and 'N' for no!");
                }
            }

            while (!Account.Logged)
            {
                Account.LoginInterface();
            }

            while (true)
            {
                Console.Write("Blog --> ");
                string input = Console.ReadLine() ?? " ";

                if (string.IsNullOrEmpty(input))
                {
                    Console.WriteLine("Thats not valid command!");
                    continue;
                }

                if (input.ToLowerInvariant().Trim() == "exit")
                {
                    break;
                }

                switch (input.ToLowerInvariant().Replace(" ", string.Empty))
                {
                case "help":
                    CommandPrinter.ShowAll();
                    break;

                case "helppost":
                    CommandPrinter.ShowPosts();
                    break;

                case "helpcomment":
                    CommandPrinter.ShowComments();
                    break;

                case "helpaccount":
                    CommandPrinter.ShowAccounts();
                    break;

                case "helpview":
                    CommandPrinter.ShowView();
                    break;

                case "postcreate":
                    Post.BeginCreatingPost();
                    break;

                case "myposts":
                    Blog.ViewAccountPosts();
                    break;

                case "allposts":
                    Post.ViewAllPosts();
                    break;

                case "newposts":
                    Blog.ShowLatests();
                    break;

                case "settings":
                    Account.AccountOptions();
                    break;

                case "clear":
                    Console.Clear();
                    break;

                default:
                    Console.WriteLine("Thats not valid command!");
                    break;
                }
            }
        }