using System; using System.Collections.Generic; using System.Linq; using System.Text.Json; namespace Bücherwurm { class Catalogue { private List Products {get; set;} private int NextId {get; set;} public Catalogue() { Products = new List(); NextId = 1; } public void Import(string JsonString) { var IntermediateBooks = JsonSerializer.Deserialize>(JsonString); foreach (var Ibook in IntermediateBooks) { Ibook.OverwriteNullId(NextId); Ibook.Category = "book"; NextId += 1; } Products = new List(IntermediateBooks); } public void AddBook(string Title, string Author, string Country, string ILink, string Link, string Language, int Pages, int Year) { Products.Add(new Book(NextId, Title, Author, Country, ILink, Link, Language, Pages, Year)); NextId = NextId++; } public void Add(IProduct product) { Products.Add(product); } public void Remove(int bookID) { Products.RemoveAll(book => book.ProductId == bookID); } public List GetBooks() { return Products.FindAll(prod => prod.Category == "book").Cast().ToList(); } public Book LookupBook(int bookId) { return (Book)Products.Find(book => book.ProductId == bookId && book.Category == "book"); } } }