87 lines
No EOL
2.5 KiB
C#
87 lines
No EOL
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.Json;
|
|
|
|
namespace Bücherwurm
|
|
{
|
|
class Catalogue
|
|
{
|
|
private List<IProduct> Products {get; set;}
|
|
|
|
private int NextId {get; set;}
|
|
|
|
public Catalogue()
|
|
{
|
|
Products = new List<IProduct>();
|
|
NextId = 1;
|
|
}
|
|
|
|
public void ImportBooks(string JsonString)
|
|
{
|
|
var IntermediateBooks = JsonSerializer.Deserialize<List<Book>>(JsonString);
|
|
foreach (var Ibook in IntermediateBooks)
|
|
{
|
|
Ibook.OverwriteNullId(NextId);
|
|
NextId += 1;
|
|
}
|
|
Products.AddRange(new List<IProduct>(IntermediateBooks));
|
|
var eBooks = new List<EBook>();
|
|
foreach (var book in IntermediateBooks)
|
|
{
|
|
var ebook = new EBook(book);
|
|
ebook.OverwriteNullId(NextId);
|
|
eBooks.Add(ebook);
|
|
NextId += 1;
|
|
}
|
|
Products.AddRange(new List<IProduct>(eBooks));
|
|
}
|
|
|
|
public void ImportMagazines(string JsonString)
|
|
{
|
|
var IntermediateMagazines = JsonSerializer.Deserialize<List<Magazine>>(JsonString);
|
|
foreach (var Ibook in IntermediateMagazines)
|
|
{
|
|
Ibook.OverwriteNullId(NextId);
|
|
NextId += 1;
|
|
}
|
|
Products.AddRange(new List<IProduct>(IntermediateMagazines));
|
|
var ePapers = new List<EPaper>();
|
|
foreach (var mag in IntermediateMagazines)
|
|
{
|
|
var epaper = new EPaper(mag);
|
|
epaper.OverwriteNullId(NextId);
|
|
NextId += 1;
|
|
}
|
|
Products.AddRange(new List<IProduct>(ePapers));
|
|
}
|
|
|
|
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<IProduct> GetProducts()
|
|
{
|
|
return Products;
|
|
}
|
|
|
|
public IProduct LookupProduct(int prodId)
|
|
{
|
|
return Products.Find(book => book.ProductId == prodId);
|
|
}
|
|
}
|
|
} |