コード例 #1
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;
            }
        }
コード例 #2
0
        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.");
            }
        }