public static User RegisterUser(List <string> userList) { string userInput = null; while (true) { while (true) { Welcome.ResetPage(); GetSearchResults.WriteCyanToConsole("Please enter a user name to register: "); userInput = Console.ReadLine(); if (!(userList.Contains(userInput))) { break; } else { Console.WriteLine("That name has already been registered"); GetSearchResults.WriteCyanToConsole("Press any key to continue..."); Console.ReadKey(); } } GetSearchResults.WriteCyanToConsole($"\nYou've entered {userInput}. Is this the name you want (y/n)? "); string continueCheck = Console.ReadLine(); if (!continueCheck.Equals("n", StringComparison.OrdinalIgnoreCase)) { Welcome.ResetPage(); Console.WriteLine($"Thank you for registering, {userInput}"); GetSearchResults.WriteCyanToConsole("\nPress any key to access the library catalog"); Console.ReadKey(); break; } } return(new User(userInput)); }
public static void CheckIn(List <Book> bookList, List <Book> checkedOutBooks, List <Book> checkedInBooks) { string continueCheck; do { while (true) { if (!(checkedOutBooks.Count == 0)) { Welcome.ResetPage(); Console.WriteLine("Now checking in a book\n"); PrintCheckedOutList(checkedOutBooks); GetSearchResults.WriteCyanToConsole("\nPlease choose a book to check in: "); int checkedInput; var userInput = Console.ReadLine(); if ((int.TryParse(userInput, out checkedInput)) && (int.Parse(userInput) > 0) && int.Parse(userInput) <= checkedOutBooks.Count) { Welcome.ResetPage(); checkedInput = int.Parse(userInput); checkedOutBooks[checkedInput - 1].CheckInBook(); checkedInBooks.Add(checkedOutBooks[checkedInput - 1]); checkedOutBooks.Remove(checkedOutBooks[checkedInput - 1]); break; } else { Welcome.ResetPage(); Console.WriteLine("Please choose a book by number from the list."); GetSearchResults.WriteCyanToConsole("\nPress any key to continue"); Console.ReadKey(); } } else { Welcome.ResetPage(); Console.WriteLine("You don't have anything to check in."); GetSearchResults.WriteCyanToConsole("\nPress any key to return to main menu."); Console.ReadKey(); return; } } GetSearchResults.WriteCyanToConsole("\nWould you like to check another book in? (y/n)? "); continueCheck = Console.ReadLine(); } while (!continueCheck.Equals("n", StringComparison.OrdinalIgnoreCase)); }
public static void UserStatus(List <Book> checkedOutBooks) { Welcome.ResetPage(); if (!checkedOutBooks.Any()) { Console.WriteLine("You don't currently have anything checked out."); } else { Console.WriteLine("You currently have the following books checked out:\n"); PrintCheckedOutList(checkedOutBooks); } GetSearchResults.WriteCyanToConsole("\nPress any key to view the library catalog"); Console.ReadKey(); }
public static void AddBook(List <Book> bookList, List <Book> checkedInBooks) { Welcome.ResetPage(); var donatedBook = new Book(); GetSearchResults.WriteCyanToConsole("Please enter the name of the book you're donating: "); donatedBook.Title = Console.ReadLine(); GetSearchResults.WriteCyanToConsole("Please enter the author of the book you're donating: "); donatedBook.Author = Console.ReadLine(); donatedBook.Status = "in"; bookList.Add(donatedBook); checkedInBooks.Add(donatedBook); Console.WriteLine("\nThank you for your donation!"); GetSearchResults.WriteCyanToConsole("\nPress any key to continue"); Console.ReadKey(); }
public static User LogIn(List <string> userList, List <Book> bookList) { string userName = null; while (true) { Welcome.ResetPage(); GetSearchResults.WriteCyanToConsole("Please enter your name to login to the library database: "); userName = Console.ReadLine(); if (userList.Contains(userName)) { var user = new User(userName); Console.WriteLine($"Welcome back, {user.Name}"); return(user); } else { Welcome.ResetPage(); Console.WriteLine("Cannot find user name.\n"); while (true) { Console.WriteLine("1 - Retry login"); Console.WriteLine("2 - Register new user"); GetSearchResults.WriteCyanToConsole("\nPlease select the one of the following options: "); string userSelection = Console.ReadLine(); if (userSelection == "1") { break; } else if (userSelection == "2") { return(RegisterUser(userList)); } else { Welcome.ResetPage(); Console.WriteLine("Sorry, I didn't get that."); } } } } }
public static int WelcomeUser() { int checkSearchInput; while (true) { ResetPage(); Console.WriteLine("Welcome to the Library's main page\n (1) Search by author\n (2) Search by title\n (3) Display all book information\n (4) Return a book\n (5) Check out a book\n (6) Donate book to library\n (7) Exit Program"); GetSearchResults.WriteCyanToConsole("\nPlease select an option from the list above: "); var searchInput = Console.ReadLine(); if ((int.TryParse(searchInput, out checkSearchInput)) && (int.Parse(searchInput) > 0) && (int.Parse(searchInput) <= 7)) { checkSearchInput = int.Parse(searchInput); break; } else { Console.WriteLine("Please choose a valid entry from the list."); GetSearchResults.WriteCyanToConsole("Press any key to continue"); Console.ReadKey(); } } return(checkSearchInput); }