Ejemplo n.º 1
0
        private void PrepareEdit(out int bookISBN, out EditOptions editOptions)
        {
            int.TryParse(mainMenuView.GetUserInput("Type book ISBN: "), out bookISBN);
            editBookView.PrintMenu();
            int sthToEdit;

            int.TryParse(mainMenuView.GetUserInput("What do you want to edit? "), out sthToEdit);
            editOptions = (EditOptions)sthToEdit;
        }
Ejemplo n.º 2
0
        public void RunMainController()
        {
            bool isMainControllerActive = true;

            while (isMainControllerActive)
            {
                mainMenuView.PrintMenu();
                int.TryParse(mainMenuView.GetUserInput("Your choice: "), out int userChoice);
                MainMenuChoice mainMenu = (MainMenuChoice)userChoice;

                switch (mainMenu)
                {
                case MainMenuChoice.Add:
                {
                    PreapareBookDeatalis(out long ISBN, out string first_name, out string surname, out string publisher, out string title, out int year, out double price);

                    createBook.AddAuthor(first_name, surname);
                    createBook.AddPublisher(publisher);
                    createBook.AddBook(ISBN, title, year, price, first_name, surname, publisher);
                    break;
                }

                case MainMenuChoice.Edit:
                {
                    PrepareEdit(out int ISBN, out EditOptions editOptions);
                    switch (editOptions)
                    {
                    case EditOptions.FirstName:
                        ChangeFirstName(ISBN);
                        break;

                    case EditOptions.Title:
                        ChangeTitle(ISBN);
                        break;

                    case EditOptions.Surname:
                        ChangeSurname(ISBN);
                        break;

                    case EditOptions.Price:
                        ChangeAPrice(ISBN);
                        break;
                    }
                    break;
                }

                case MainMenuChoice.Delete:
                {
                    int.TryParse(mainMenuView.GetUserInput("Type a ISBN: "), out int ISBN);
                    IDelateBook delateBook = (IDelateBook)editBook;
                    delateBook.RemoveBook(ISBN);
                    break;
                }

                case MainMenuChoice.SeeAllBooksByAuthor:
                    string      author = this.mainMenuView.GetUserInput("Type author: ");
                    List <Book> books  = readBook.GetBooksByAuthor(author);
                    mainMenuView.PrintBooks(books);
                    break;

                case MainMenuChoice.Sort:
                    List <Book> bookAscendigByTitle = readBook.GetBooksAscendigByTitle();
                    this.mainMenuView.PrintBooks(bookAscendigByTitle);
                    break;

                case MainMenuChoice.BooksCreatedByAuthor:
                    string      authors             = mainMenuView.GetAuthors();
                    List <Book> bookCreatedByAuthor = readBook.GetBooksByAuthors(authors);
                    this.mainMenuView.PrintBooks(bookCreatedByAuthor);
                    break;

                case MainMenuChoice.BooksFromLastXYears:
                    int         xYears = int.Parse(mainMenuView.GetUserInput("Type number of years: "));
                    List <Book> booksFromLastTenYears = readBook.GetBooksFromLastXYears(xYears);
                    mainMenuView.PrintBooks(booksFromLastTenYears);
                    break;

                case MainMenuChoice.ValueOfLibrary:
                    decimal valueOfLibrary = editBook.GetLibraryValue();
                    mainMenuView.PrintMessage($"Total value of yours Library is: {valueOfLibrary}");
                    break;

                case MainMenuChoice.Exit:
                    isMainControllerActive = false;
                    break;

                default:
                    mainMenuView.PrintMessage("No option. Please try again");
                    break;
                }
            }
        }