2020-04-23 13:44:38 +00:00
|
|
|
using System;
|
2020-04-23 12:47:50 +00:00
|
|
|
using System.Collections.Generic;
|
2020-04-27 09:26:45 +00:00
|
|
|
using System.Text.Json;
|
2020-04-23 12:47:50 +00:00
|
|
|
|
|
|
|
namespace Bücherwurm
|
|
|
|
{
|
|
|
|
class Catalogue
|
|
|
|
{
|
|
|
|
private List<Book> Books {get; set;}
|
|
|
|
|
2020-04-23 13:44:38 +00:00
|
|
|
private int NextId {get; set;}
|
|
|
|
|
2020-04-23 12:47:50 +00:00
|
|
|
public Catalogue()
|
|
|
|
{
|
|
|
|
Books = new List<Book>();
|
2020-04-27 09:26:45 +00:00
|
|
|
NextId = 1;
|
2020-04-23 12:47:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Import(string JsonString)
|
|
|
|
{
|
2020-04-27 09:26:45 +00:00
|
|
|
var intermediateBooks = JsonSerializer.Deserialize<List<Book>>(JsonString);
|
|
|
|
foreach (var ibook in intermediateBooks)
|
|
|
|
{
|
|
|
|
ibook.OverwriteNullId(NextId);
|
|
|
|
NextId = NextId + 1;
|
|
|
|
}
|
|
|
|
Books = intermediateBooks;
|
2020-04-23 12:47:50 +00:00
|
|
|
}
|
2020-04-23 13:44:38 +00:00
|
|
|
|
|
|
|
public void Add(string Title, string Author,
|
|
|
|
string Country, string ILink, string Link,
|
|
|
|
string Language, int Pages, int Year)
|
|
|
|
{
|
|
|
|
Books.Add(new Book(NextId, Title, Author, Country, ILink, Link, Language, Pages, Year));
|
|
|
|
NextId = NextId++;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Remove(int BookID)
|
|
|
|
{
|
|
|
|
Books.RemoveAll(book => book.BookId == BookID);
|
|
|
|
}
|
2020-04-24 13:54:17 +00:00
|
|
|
|
|
|
|
public List<Book> GetBooks()
|
|
|
|
{
|
|
|
|
return Books;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Book LookupBook(int BookId)
|
|
|
|
{
|
|
|
|
return Books.Find(book => book.BookId == BookId);
|
|
|
|
}
|
2020-04-23 12:47:50 +00:00
|
|
|
}
|
|
|
|
}
|