static void Main(string[] args) { ValidatorClass validation = new ValidatorClass(); LibraryApp session = new LibraryApp(); session.StartLibrary(); }
//should allow user to see a list item based on a search for author or title private void SearchForItem() //will need a 'List<Item> libraryList' parameter { ValidatorClass session = new ValidatorClass(); Console.WriteLine("Search by:\n 1. Author\n 2: Title\n 3. Return to Main Menu"); int userInput = this.session.GetValidInput(this.session.GetUserInput("User Option: "), 1, 3); switch (userInput) { case 1: string userAuthor = session.GetUserInput("Enter the name of the author: "); session.SearchByAuthor(libraryList, userAuthor); UserContinue(); break; case 2: string userTitle = session.GetUserInput("Enter the name of the title: "); session.SearchByTitle(libraryList, userTitle); UserContinue(); break; case 3: PrintMainMenu(); break; } }
public int GetValidInput(string input, int min, int max) { ValidatorClass session = new ValidatorClass(); try { int selection = int.Parse(input); if (selection >= min && selection <= max) { return(selection); } else { return(GetValidInput(session.GetUserInput($"Please enter an option between {min} - {max}: "), min, max)); } } catch (FormatException) { return(GetValidInput(session.GetUserInput($"Please enter an option of {min} - {max}: "), min, max)); } }
private void CheckInItem() //will need a 'List<Item> libraryList' parameter { ValidatorClass session = new ValidatorClass(); //do stuff // probably print the list of items that checked in Console.WriteLine("\nHere's the list of currently checked out items:"); int count = 1; Dictionary <int, string> tempDict = new Dictionary <int, string>(); foreach (Item item in libraryList) { if (item.CheckedIn == false) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{count}: {item.Title}"); Console.ResetColor(); tempDict.Add(count, item.Title); count++; } } int choice = session.GetValidInput("\nWhich item would you like to check out?", 1, count - 1); bool gotValue = tempDict.TryGetValue(choice, out string title); foreach (var item in libraryList) { if (item.Title == title) { item.CheckedIn = true; SetItemDueDate(item); } } UserContinue(); }