//method for book selection, checkout and error handling public void CheckoutBook() { BookCheckoutListView bclv = new BookCheckoutListView(LibraryDb); bclv.Display(); //int numberOfCheckedOutBooks = CheckoutBookList.Count; int userInput = GetIntFromUser(1, LibraryDb.Count);//Get which book to checkout if (userInput != -1) { Book selectedBook = LibraryDb[userInput - 1]; //store the book in an easier to read variable bool onShelf = selectedBook.Status; //Store the checked out status in an easier to read variable bool onHold = selectedBook.HoldStatus; //Store the hold status in an easier to read variable //Check the status of selected book and display appropriate message when they try to check out a book if (onShelf == false && onHold == true) { BookErrorView bev = new BookErrorView($"Sorry that book is already checked out and on hold. Check back after {selectedBook.DueDate.AddDays(14).ToShortDateString()}"); bev.Display(); } else if (onShelf == false && onHold == false) { bool response1 = GetYesOrNoFromUser("Do you want to place this book on hold?"); if (response1 == true) { selectedBook.HoldStatus = true; Console.Clear(); Console.WriteLine("Your book has been placed on hold. We will notify you when available."); } } else { CheckoutBookList.Add(selectedBook); selectedBook.Status = false; selectedBook.DueDate = DateTime.Now.AddDays(14); SaveToCSV(); } } //Display books currently checked out. BookCheckoutCartListView bcclv = new BookCheckoutCartListView(LibraryDb); bcclv.Display(); bool response = GetYesOrNoFromUser("Do you want to check out another book?"); //Gets yes or no from user //leftover books to choose from to add to cart again if (response == true) { CheckoutBook(); } //Save the checkout status to csv SaveToCSV(); ReturnToMainMenuPrompt(); }
//method for searching a book and error for search parameters public void SearchBook(string searchType) { //searchView changes depending on what is being searched. //generic Iview is used to store different views depending on search type. IView searchView = new SearchView(searchType); if (searchType == "Dewey") { searchView = new BookSearchDeweyView(); } searchView.Display(); //no user input needed for search all books string userInput = ""; if (!(searchType == "All")) { userInput = Console.ReadLine().ToLower(); } bool foundBook = false; for (int i = 0; i < LibraryDb.Count; i++) { bool matchingSearchFound = false; Book selectedBook = LibraryDb[i]; if (searchType == "All") { matchingSearchFound = true; } else if (searchType == "Title") { matchingSearchFound = selectedBook.Title.ToLower().Contains(userInput); } else if (searchType == "Author") { matchingSearchFound = selectedBook.Author.ToLower().Contains(userInput); } else if (searchType == "Genre") { matchingSearchFound = selectedBook.Genre.ToLower().Contains(userInput); } else if (searchType == "Dewey") { matchingSearchFound = selectedBook.DeweySystem.ToLower().Contains(userInput); } if (matchingSearchFound) { foundBook = true; BookView bv = new BookView(selectedBook); bv.Display(); } } if (!foundBook) { BookErrorView bev = new BookErrorView($"No book found based on your search parameters."); bev.Display(); } ReturnToMainMenuPrompt(); }