53 lines
No EOL
1.3 KiB
C#
53 lines
No EOL
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text.Json;
|
|
|
|
namespace Bücherwurm
|
|
{
|
|
class Catalogue
|
|
{
|
|
private List<Book> Books {get; set;}
|
|
|
|
private int NextId {get; set;}
|
|
|
|
public Catalogue()
|
|
{
|
|
Books = new List<Book>();
|
|
NextId = 1;
|
|
}
|
|
|
|
public void Import(string JsonString)
|
|
{
|
|
var intermediateBooks = JsonSerializer.Deserialize<List<Book>>(JsonString);
|
|
foreach (var ibook in intermediateBooks)
|
|
{
|
|
ibook.OverwriteNullId(NextId);
|
|
NextId = NextId + 1;
|
|
}
|
|
Books = intermediateBooks;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
public List<Book> GetBooks()
|
|
{
|
|
return Books;
|
|
}
|
|
|
|
public Book LookupBook(int BookId)
|
|
{
|
|
return Books.Find(book => book.BookId == BookId);
|
|
}
|
|
}
|
|
} |