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(); }
public static List <Book> ReadXML(string filePath) { TextReader reader = null; try { var serializer = new XmlSerializer(typeof(List <Book>)); reader = new StreamReader(filePath); return((List <Book>)serializer.Deserialize(reader)); } catch { Console.Write("Do you want to create New file? (Y/N)"); if (Vaildation.IsYorN(Console.ReadLine())) { WriteXML(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "//" + Program.fileName + ".xml", CardCatalog.myBooks); } else { Environment.Exit(0); } return(CardCatalog.myBooks); } finally { if (reader != null) { reader.Close(); } } }