public static Dictionary <int, Book> ReturnBook(Dictionary <int, Book> bookList) { Console.WriteLine("How would you like to search for a book to return? (title or author)"); string userInput = Validator.DetermineTitleOrAuthor(); if (userInput == "title") { Console.Write("Enter title of the book: "); userInput = Console.ReadLine(); bool validTitle; if (validTitle = Validator.BookTitleValidator(bookList, userInput)) { int bookKey = BookApp.FindBookByTitle(bookList, userInput); bookList = BookApp.ReturnBook(bookList, bookKey); } } else if (userInput == "author") { Console.Write("Enter author name: "); userInput = Console.ReadLine(); bool validAuthor; if (validAuthor = Validator.BookAuthorValidator(bookList, userInput)) { int bookKey = BookApp.FindBookByAuthor(bookList, userInput); bookList = BookApp.ReturnBook(bookList, bookKey); } } else { Console.WriteLine("Sorry, not valid"); } return(bookList); }
static void Main(string[] args) { string path = FileManagement.GetPath(); List <string> listOfStrings = FileManagement.ReadFile(path); Dictionary <int, Book> bookList = ParseFile.ConvertToBook(listOfStrings); bookList = BookApp.CheckInBooks(bookList); bool keepGoing = true; while (keepGoing == true) { BookApp.PrintMenu(); int menuChoice = Validator.MenuChoice(); switch (menuChoice) { case 1: //Display book list BookApp.DisplayBooks(bookList); break; case 2: //Search by author bookList = ProgramApp.SearchByAuthor(bookList); break; case 3: //search by title bookList = ProgramApp.SearchByTitle(bookList); break; case 4: //check out book bookList = ProgramApp.CheckOutBook(bookList); break; case 5: //return book bookList = ProgramApp.ReturnBook(bookList); break; case 6: bookList = ProgramApp.AddBook(bookList); break; case 7: ProgramApp.EasterEgg(); break; default: Console.WriteLine("Sorry, that wasn't a valid choice."); break; } keepGoing = BookApp.ContinueTheProgram(); Console.Clear(); } listOfStrings = FileManagement.CreateListFromDictonary(bookList); FileManagement.WriteFile(listOfStrings, path); Console.ReadLine(); }
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); }