From c0c12cba82b072e45b1d232b13214f0aa7f33eb8 Mon Sep 17 00:00:00 2001 From: nek0 Date: Tue, 28 Apr 2020 10:54:22 +0200 Subject: [PATCH] Lending works --- .vscode/launch.json | 2 +- Administration.cs | 12 ++++++++---- Book.cs | 3 +++ Catalogue.cs | 5 +++-- IProduct.cs | 2 ++ Inventory.cs | 9 +++++++-- Item.cs | 4 ++-- Lend_Administration.cs | 4 ++-- Lending.cs | 8 ++++---- 9 files changed, 32 insertions(+), 17 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index fcb621e..80949b2 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -14,7 +14,7 @@ "args": ["books.json"], "cwd": "${workspaceFolder}", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console - "console": "internalConsole", + "console": "integratedTerminal", "stopAtEntry": false }, { diff --git a/Administration.cs b/Administration.cs index 95db5fa..edd188c 100644 --- a/Administration.cs +++ b/Administration.cs @@ -105,7 +105,7 @@ namespace Bücherwurm { Console.WriteLine("---"); Console.WriteLine("ID: {0}", item.ItemId); - Console.WriteLine("BuchID: {0}", item.BookId); + Console.WriteLine("BuchID: {0}", item.ProdId); var Status = ""; switch (item.Status) { @@ -129,7 +129,7 @@ namespace Bücherwurm { Console.WriteLine("Bitte geben sie die BuchID an:"); var BookId = int.Parse(Console.ReadLine()); - var Book = Catalogue.LookupBook(BookId); + var Book = Catalogue.LookupProduct(BookId); if (Book != null) { Inventory.Add(Book); @@ -166,7 +166,7 @@ namespace Bücherwurm { Console.WriteLine("---"); Console.WriteLine("AusleiheID: {0}", lending.LendId); - Console.WriteLine("Ausgeliehene Exemplare: {0}", lending.LendItems); + Console.WriteLine("Ausgeliehenes Exemplar: {0}", lending.LendItem); Console.WriteLine("Rückgabedatum: {0}", lending.ReturnDate); Console.WriteLine("Ausleihender Kunde: {0}", lending.Customer); } @@ -198,7 +198,11 @@ namespace Bücherwurm } while (Input != ""); Console.WriteLine("Bitte geben Sie den Kundennamen an:"); var Customer = Console.ReadLine(); - Lendings.Lend(LendList.ToArray(), Customer); + foreach (int id in LendList) + { + int time = Catalogue.LookupProduct(Inventory.LookupItem(id).ProdId).LendTime; + Lendings.Lend(id, Customer, time); + } Console.WriteLine("Ausleihe erfolgreich!"); } diff --git a/Book.cs b/Book.cs index 64f5814..5ccbf6d 100644 --- a/Book.cs +++ b/Book.cs @@ -30,6 +30,8 @@ namespace Bücherwurm public string Category { get; set; } [JsonPropertyName("imageLink")] public string ImageLink { get; set; } + [JsonIgnore] + public int LendTime {get; set;} public Book(int Id, string Title, string Author, string Country, string ILink, string Link, string Language, @@ -37,6 +39,7 @@ namespace Bücherwurm { ProductId = Id; Category = "book"; + LendTime = 30; this.Title = Title; this.Author = Author; this.Country = Country; diff --git a/Catalogue.cs b/Catalogue.cs index f456320..793bbee 100644 --- a/Catalogue.cs +++ b/Catalogue.cs @@ -24,6 +24,7 @@ namespace Bücherwurm { Ibook.OverwriteNullId(NextId); Ibook.Category = "book"; + Ibook.LendTime = 30; NextId += 1; } Products = new List(IntermediateBooks); @@ -52,9 +53,9 @@ namespace Bücherwurm return Products.FindAll(prod => prod.Category == "book").Cast().ToList(); } - public Book LookupBook(int bookId) + public IProduct LookupProduct(int prodId) { - return (Book)Products.Find(book => book.ProductId == bookId && book.Category == "book"); + return Products.Find(book => book.ProductId == prodId); } } } \ No newline at end of file diff --git a/IProduct.cs b/IProduct.cs index fa4b02a..7029cd9 100644 --- a/IProduct.cs +++ b/IProduct.cs @@ -8,6 +8,8 @@ namespace Bücherwurm string ImageLink { get; set;} + int LendTime {get; set;} + void OverwriteNullId(int id); } } \ No newline at end of file diff --git a/Inventory.cs b/Inventory.cs index cb7483b..8fe153f 100644 --- a/Inventory.cs +++ b/Inventory.cs @@ -30,9 +30,9 @@ namespace Bücherwurm InventoryList.RemoveAll(item => item.ItemId == Id); } - public void BookRemove(int BookId) + public void BookRemove(int ProdId) { - InventoryList.RemoveAll(item => item.BookId == BookId); + InventoryList.RemoveAll(item => item.ProdId == ProdId); } public List GetInventory() @@ -49,5 +49,10 @@ namespace Bücherwurm { return (InventoryList.Find(item => item.ItemId == Id && item.Status == StatusEnum.Available) != null); } + + public Item LookupItem(int ItemId) + { + return InventoryList.Find(item => ItemId == item.ItemId); + } } } \ No newline at end of file diff --git a/Item.cs b/Item.cs index 4077399..af1f57e 100644 --- a/Item.cs +++ b/Item.cs @@ -4,14 +4,14 @@ namespace Bücherwurm { public int ItemId {get;} - public int BookId {get;} + public int ProdId {get;} public StatusEnum Status {get; set;} public Item(int Id, int BookId) { ItemId = Id; - this.BookId = BookId; + this.ProdId = BookId; Status = StatusEnum.Available; } } diff --git a/Lend_Administration.cs b/Lend_Administration.cs index 1293b9e..8f15511 100644 --- a/Lend_Administration.cs +++ b/Lend_Administration.cs @@ -17,9 +17,9 @@ namespace Bücherwurm NextId = 1; } - public void Lend(int[] ItemIds, string Customer) + public void Lend(int ItemId, string Customer, int timeInDays) { - Lendings.Add(new Lending(NextId, ItemIds, Customer)); + Lendings.Add(new Lending(NextId, ItemId, Customer, timeInDays)); ActiveLendings.Add(NextId); NextId = NextId + 1; } diff --git a/Lending.cs b/Lending.cs index 81f74c3..59f4163 100644 --- a/Lending.cs +++ b/Lending.cs @@ -6,17 +6,17 @@ namespace Bücherwurm { public int LendId {get;} - public int[] LendItems {get; set;} + public int LendItem {get; set;} public DateTime ReturnDate {get;} public string Customer {get; } - public Lending(int Id, int[] Items, string Customer) + public Lending(int Id, int Item, string Customer, int timeInDays) { LendId = Id; - LendItems = Items; - ReturnDate = DateTime.Now.AddDays(30); + LendItem = Item; + ReturnDate = DateTime.Now.AddDays(timeInDays); this.Customer = Customer; } }