diff --git a/Administration.cs b/Administration.cs index 136ff20..95db5fa 100644 --- a/Administration.cs +++ b/Administration.cs @@ -25,7 +25,7 @@ namespace Bücherwurm foreach (var book in BookList) { Console.WriteLine("---"); - Console.WriteLine("ID: {0}", book.BookId); + Console.WriteLine("ID: {0}", book.ProductId); Console.WriteLine("Author: {0}", book.Author); Console.WriteLine("Titel: {0}", book.Title); } @@ -71,7 +71,7 @@ namespace Bücherwurm case "j": { Correct = true; - Catalogue.Add(Title, Author, Country, ImgLink, Link, Language, int.Parse(Pages), int.Parse(Year)); + Catalogue.AddBook(Title, Author, Country, ImgLink, Link, Language, int.Parse(Pages), int.Parse(Year)); Console.WriteLine("Buch wurde hinzugefügt."); break; } diff --git a/Book.cs b/Book.cs index b6e443d..9079476 100644 --- a/Book.cs +++ b/Book.cs @@ -2,11 +2,8 @@ using System.Text.Json.Serialization; namespace Bücherwurm { - class Book + class Book : IProduct { - [JsonIgnoreAttribute] - public int BookId {get; set;} - [JsonPropertyName("title")] public string Title {get; set;} @@ -16,9 +13,6 @@ namespace Bücherwurm [JsonPropertyName("country")] public string Country {get; set;} - [JsonPropertyName("imageLink")] - public string ImageLink {get; set;} - [JsonPropertyName("link")] public string Link {get; set;} @@ -30,12 +24,19 @@ namespace Bücherwurm [JsonPropertyName("year")] public int Year {get; set;} + [JsonIgnore] + public int ProductId { get; set; } + [JsonIgnore] + public string Category { get; } + [JsonPropertyName("imageLink")] + public string ImageLink { get; set; } public Book(int Id, string Title, string Author, string Country, string ILink, string Link, string Language, int Pages, int Year) { - BookId = Id; + ProductId = Id; + Category = "book"; this.Title = Title; this.Author = Author; this.Country = Country; @@ -50,12 +51,12 @@ namespace Bücherwurm { } - - public void OverwriteNullId(int Id) + + public void OverwriteNullId(int id) { - if (BookId == 0) + if (ProductId == 0) { - BookId = Id; + ProductId = id; } } } diff --git a/Catalogue.cs b/Catalogue.cs index e5a404d..d4ef2cb 100644 --- a/Catalogue.cs +++ b/Catalogue.cs @@ -1,53 +1,59 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text.Json; namespace Bücherwurm { class Catalogue { - private List Books {get; set;} + private List Products {get; set;} private int NextId {get; set;} public Catalogue() { - Books = new List(); + Products = new List(); NextId = 1; } public void Import(string JsonString) { - var intermediateBooks = JsonSerializer.Deserialize>(JsonString); - foreach (var ibook in intermediateBooks) + var IntermediateBooks = JsonSerializer.Deserialize>(JsonString); + foreach (var Ibook in IntermediateBooks) { - ibook.OverwriteNullId(NextId); - NextId = NextId + 1; + Ibook.OverwriteNullId(NextId); + NextId += 1; } - Books = intermediateBooks; + Products = IntermediateBooks; } - public void Add(string Title, string Author, + public void AddBook(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)); + Products.Add(new Book(NextId, Title, Author, Country, ILink, Link, Language, Pages, Year)); NextId = NextId++; } - public void Remove(int BookID) + public void Add(IProduct product) { - Books.RemoveAll(book => book.BookId == BookID); + Products.Add(product); + } + + public void Remove(int bookID) + { + Products.RemoveAll(book => book.ProductId == bookID); } public List GetBooks() { - return Books; + return Products.FindAll(prod => prod.Category == "book").Cast().ToList(); } - public Book LookupBook(int BookId) + public Book LookupBook(int bookId) { - return Books.Find(book => book.BookId == BookId); + return (Book)Products.Find(book => book.ProductId == bookId && book.Category == "book"); } } } \ No newline at end of file diff --git a/Inventory.cs b/Inventory.cs index 2bc6c85..cb7483b 100644 --- a/Inventory.cs +++ b/Inventory.cs @@ -13,9 +13,9 @@ namespace Bücherwurm NextId = 1; } - public void Add(Book Book) + public void Add(IProduct Book) { - InventoryList.Add(new Item(NextId, Book.BookId)); + InventoryList.Add(new Item(NextId, Book.ProductId)); NextId = NextId + 1; }