public static void CheckList() { Console.Clear(); Console.WriteLine("You are working in the \"{0}.xml\" file\n\n", fileName); Console.WriteLine("1) List all books."); Console.WriteLine("2) Add a book."); Console.WriteLine("3) Save and exit."); int userValue = Vaildation.IsInt(Console.ReadLine(), "Number please"); switch (userValue) { case (int)(UserOptions.listOfBooks): CardCatalog.ListBooks(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "//" + fileName + ".xml", CardCatalog.myBooks); break; case (int)(UserOptions.addBook): CardCatalog.AddBook(CardCatalog.myBooks); break; case (int)(UserOptions.saveAndExit): CardCatalog.SaveAndExit(); break; default: Console.Clear(); Console.WriteLine("Invalid number. Please enter 1, 2, or 3."); CheckList(); break; } }
public static void AddBook(List <Book> books) { Console.Clear(); Console.Write("Enter book title: "); string title = Console.ReadLine(); Console.Write("Enter author name: "); string author = Console.ReadLine(); Console.Write("Enter publishing year: "); int yearPublished = Vaildation.IsInt(Console.ReadLine(), "publishing year again"); Console.Write("Enter price: "); decimal price = Vaildation.IsDecimal(Console.ReadLine()); books.Add(new Book() { Title = title, Author = author, YearPublished = yearPublished, Price = price }); addBookCount++; Console.WriteLine("You added {0} book(s).", addBookCount); Console.Write("Do you want add another book? (Y/N)"); if (Vaildation.IsYorN(Console.ReadLine())) { AddBook(books); } Program.CheckList(); }