public static Dictionary <int, Book> CheckOutBook(Dictionary <int, Book> bookList) { Console.WriteLine("How would you like to search for a book to check out? (title or author)"); string userInput = Validator.DetermineTitleOrAuthor(); bool validTitle; bool validAuthor; if (userInput == "title") { Console.Write("Enter title of the book: "); userInput = Console.ReadLine(); if (validTitle = Validator.BookTitleValidator(bookList, userInput)) { int bookKey = BookApp.FindBookByTitle(bookList, userInput); if (bookList[bookKey].Status == true) { bookList = BookApp.CheckOutBook(bookList, bookKey); } else { Console.WriteLine("Sorry, that book is already checked out."); } } } else if (userInput == "author") { Console.Write("Enter author name: "); userInput = Console.ReadLine(); if (validAuthor = Validator.BookAuthorValidator(bookList, userInput)) { int bookKey = BookApp.FindBookByAuthor(bookList, userInput); if (bookList[bookKey].Status == true) { bookList = BookApp.CheckOutBook(bookList, bookKey); } else { Console.WriteLine("Sorry, that book is already checked out."); } } } else { Console.WriteLine("Sorry, not valid"); } return(bookList); }
public static Dictionary <int, Book> SearchByTitle(Dictionary <int, Book> bookList) { Console.Write("Enter title of the book: "); string userInput = Console.ReadLine(); bool validTitle = Validator.BookTitleValidator(bookList, userInput); if (validTitle == true) { int bookKey = BookApp.FindBookByTitle(bookList, userInput); bool onShelf = BookApp.DisplayBook(bookList, bookKey); if (onShelf) { Console.Write("Would you like to check that book out? (y/n) "); if (Validator.YesNoAnswer()) { bookList = BookApp.CheckOutBook(bookList, bookKey); } } } return(bookList); }
public static Dictionary <int, Book> ActionFromList(Dictionary <int, Book> bookList) { Console.Write("\nWould you like to select a book? (y/n) "); if (Validator.YesNoAnswer()) { bool validNumber = false; int bookNum = 0; while (validNumber == false) { Console.Write($"Please select a book 1 through {bookList.Count}: "); bool realNumber = int.TryParse(Console.ReadLine(), out bookNum); if (realNumber == true && bookNum > 0 && bookNum <= bookList.Count) { validNumber = true; } } if (bookList[bookNum].Status == true) { Console.Write("Would you like to check that book out? (y/n) "); if (Validator.YesNoAnswer()) { bookList = BookApp.CheckOutBook(bookList, bookNum); } } else if (bookList[bookNum].Status == false) { Console.Write("Would you like to return that book? (y/n) "); if (Validator.YesNoAnswer()) { bookList = BookApp.ReturnBook(bookList, bookNum); } } } return(bookList); }