public void ExecuteMainMenuChoice(MenuOptions choice, List <Book> bookList) { searchResults = new List <Book>(); switch (choice) { case MenuOptions.DisplayAll: Console.Clear(); Menu.DisplayBookList(bookList); searchResults = bookList; LibraryMember.SelectFromList(searchResults, cart); appRunning = true; return; case MenuOptions.SearchByAuthor: Console.Clear(); searchResults = LibraryMember.MemberSearchByAuthor(bookList); LibraryMember.SelectFromList(searchResults, cart); appRunning = true; return; case MenuOptions.SearchByTitle: Console.Clear(); searchResults = LibraryMember.MemberSearchByTitle(bookList); LibraryMember.SelectFromList(searchResults, cart); appRunning = true; return; case MenuOptions.GoToCart: Console.Clear(); Cart.BringUpCart(cart); appRunning = true; SaveLoad.Save(bookList); return; case MenuOptions.ManageLibrary: Console.Clear(); AddRemove.ManageLibrary(bookList); appRunning = true; SaveLoad.Save(bookList); return; case MenuOptions.Quit: appRunning = false; SaveLoad.Save(bookList); return; default: return; } }
public static void RemoveBook(List <Book> books) { Console.Clear(); Console.WriteLine("How do you want to find a book to remove?"); Console.WriteLine("1. Display all books"); Console.WriteLine("2. Search by author"); Console.WriteLine("3. Search by title"); Book selectedBook = new Book("title", "author", false); List <Book> searchResults; bool isValidRenameOption = false; do { switch (Console.ReadLine().ToLower()) { case "one": case "1": Console.Clear(); Console.WriteLine("Select a book to remove."); Menu.DisplayBookList(books); selectedBook = LibraryMember.SelectBook(books); isValidRenameOption = true; break; case "two": case "2": Console.Clear(); Console.WriteLine("Search an author and select a book to remove."); searchResults = LibraryMember.MemberSearchByAuthor(books); if (searchResults.Count == 0) { return; } selectedBook = LibraryMember.SelectBook(searchResults); isValidRenameOption = true; break; case "three": case "3": Console.Clear(); Console.WriteLine("Search a title and select a book to remove."); selectedBook = LibraryMember.SelectBook(LibraryMember.MemberSearchByTitle(books)); isValidRenameOption = true; break; default: Console.WriteLine("That is not a valid entry. Please try again:"); isValidRenameOption = false; break; } } while (!isValidRenameOption); Console.WriteLine($"Are you sure you want to remove {selectedBook.Title} from the library? [Y/N]"); bool validInput = false; do { string userInput = Console.ReadLine(); if ((userInput.Equals("Y", StringComparison.OrdinalIgnoreCase))) { books.Remove(selectedBook); validInput = true; } else if ((userInput.Equals("N", StringComparison.OrdinalIgnoreCase))) { return; } else { Console.WriteLine("Not a valid input, try again."); validInput = false; } } while(!validInput); Console.WriteLine($"You've removed {selectedBook.Title} from the library."); Console.WriteLine("Press enter to continue"); Console.ReadLine(); }