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 ImportBooks(string JsonString) { var IntermediateBooks = JsonSerializer.Deserialize>(JsonString); foreach (var Ibook in IntermediateBooks) { Ibook.OverwriteNullId(NextId); NextId += 1; } Products.AddRange(new List(IntermediateBooks)); var eBooks = new List(); foreach (var book in IntermediateBooks) { var ebook = new EBook(book); ebook.OverwriteNullId(NextId); eBooks.Add(ebook); NextId += 1; } Products.AddRange(new List(eBooks)); } public void ImportMagazines(string JsonString) { var IntermediateMagazines = JsonSerializer.Deserialize>(JsonString); foreach (var Ibook in IntermediateMagazines) { Ibook.OverwriteNullId(NextId); NextId += 1; } Products.AddRange(new List(IntermediateMagazines)); var ePapers = new List(); foreach (var mag in IntermediateMagazines) { var epaper = new EPaper(mag); epaper.OverwriteNullId(NextId); ePapers.Add(epaper); NextId += 1; } Products.AddRange(new List(ePapers)); } public void AddManualBook( string Title, string Author, string Country, string ILink, string Link, string Language, int Pages, int Year) { var newBook = new Book(NextId, Title, Author, Country, ILink, Link, Language, Pages, Year); Products.Add(newBook); NextId += 1; var newEBook = new EBook(newBook); newEBook.OverwriteNullId(NextId); Products.Add(newBook); NextId += 1; } public void AddManualMagazine( string Title, string Run, string Audience, string Topic) { var newMagazine = new Magazine(NextId, Title, Run, Audience, Topic); Products.Add(newMagazine); NextId += 1; var newEPaper = new EPaper(newMagazine); newEPaper.OverwriteNullId(NextId); Products.Add(newEPaper); NextId += 1; } public void Add(IProduct product) { Products.Add(product); } public void Remove(int bookID) { Products.RemoveAll(book => book.ProductId == bookID); } public List GetProducts() { return Products; } public IProduct LookupProduct(int prodId) { return Products.Find(book => book.ProductId == prodId); } } }