Ejemplo n.º 1
0
        private void ShowInitialWindow()
        {
            ConsoleNoteHelper.InitHeader();

            Console.WriteLine("#################################################################");
            Console.WriteLine("#                       Enter command                           #");
            Console.WriteLine($"#               Enter '{nameof(Command.Help)}', if you need help                  #");
            Console.WriteLine("#################################################################");
            Console.Write("> ");
        }
        public void AddNote()
        {
            ConsoleNoteHelper.InitHeader();

            var author = GetConsoleString("Enter your name");
            var title  = GetConsoleString("Enter note title");
            var text   = GetConsoleString("Enter note text");

            _noteRepository.AddNote(author, title, text);

            Console.WriteLine("Note was added.");
        }
        public void Help()
        {
            ConsoleNoteHelper.InitHeader();

            Console.WriteLine("#################################################################");
            Console.WriteLine("#                        List of command                        #");
            Console.WriteLine($"#  1. Enter '{nameof(Command.Add)}', if you need to create new note               #");
            Console.WriteLine($"#  2. Enter '{nameof(Command.List)}', if you need to show all created notes       #");
            Console.WriteLine($"#  3. Enter '{nameof(Command.Delete)}', if you need to delete note                #");
            Console.WriteLine($"#  4. Enter '{nameof(Command.Edit)}', if you need to change text note             #");
            Console.WriteLine($"#  5. Enter '{nameof(Command.Help)}', if you need help                            #");
            Console.WriteLine("#################################################################");
        }
Ejemplo n.º 4
0
        public void Handle(Command command)
        {
            switch (command)
            {
            case Command.Add:
                _noteController.AddNote();

                Console.WriteLine("Do you want to add another note? (y/n)");
                ActionHelper.DoActionOnResponse(Console.ReadLine(), () => { Handle(Command.Add); }, () => { ConsoleNoteHelper.InitHeader(); });

                break;

            case Command.List:
                _noteController.ShowNotes();

                Console.WriteLine("Press any key to return to the main window...");
                Console.ReadKey();
                ActionHelper.DoActionOnResponse("y", () => { ConsoleNoteHelper.InitHeader(); }, () => { });

                break;

            case Command.Delete:
                _noteController.DeleteNote();

                Console.WriteLine("Do you want to delete another note? (y/n)");
                ActionHelper.DoActionOnResponse(Console.ReadLine(), () => { Handle(Command.Delete); }, () => { ConsoleNoteHelper.InitHeader(); });

                break;

            case Command.Edit:
                _noteController.EditNote();

                Console.WriteLine("Do you want to edit another note? (y/n)");
                ActionHelper.DoActionOnResponse(Console.ReadLine(), () => { Handle(Command.Edit); }, () => { ConsoleNoteHelper.InitHeader(); });

                break;

            case Command.Help:
                _noteController.Help();

                Console.WriteLine("Press any key to return to the main window...");
                Console.ReadKey();
                ActionHelper.DoActionOnResponse("y", () => { ConsoleNoteHelper.InitHeader(); }, () => { });

                break;
            }
        }
        public void EditNote()
        {
            Console.WriteLine("Please enter id of note to edit:");
            var successfulParsing = Int32.TryParse(Console.ReadLine(), out var id);

            if (successfulParsing)
            {
                var isExist = _noteRepository.IsNoteExist(id);

                if (isExist)
                {
                    var toEdit = _noteRepository.GetNote(id);
                    Console.WriteLine($"Current title of this note: {toEdit.Title}. Pick a new title:");
                    Console.Write("> ");

                    var newTitle = Console.ReadLine();
                    Console.WriteLine($"Are you sure (y/n)?");

                    var response = Console.ReadLine();

                    Action actionYes = () =>
                    {
                        Console.WriteLine("Title was successfully changed.");
                        Console.WriteLine("Current text of this note:");
                        Console.WriteLine(toEdit.Text);
                        Console.WriteLine("Now you can change the text:");
                        Console.Write("> ");

                        var newText = Console.ReadLine();
                        _noteRepository.EditNote(toEdit.Id, newTitle, newText);
                        Console.WriteLine("Text was successfully changed.");
                    };

                    ActionHelper.DoActionOnResponse(response, actionYes, () => { ConsoleNoteHelper.InitHeader(); });
                }
                else
                {
                    Console.WriteLine($"The note with id [{id}] is not exist in the list of notes.");
                }
            }
            else
            {
                Console.WriteLine($"Id [{id}] is not a number.");
            }
        }