From 7cd70212a4073e459378e628eee2b52069cfa54b Mon Sep 17 00:00:00 2001 From: nek0 Date: Tue, 28 Apr 2020 17:22:11 +0200 Subject: [PATCH] finish implementation of electronic media --- .vscode/launch.json | 2 +- Administration.cs | 54 ++++++++++++++++++++++++++++++++++++--------- Catalogue.cs | 1 + Inventory.cs | 33 ++++++++++++++++++++++++--- Program.cs | 2 +- 5 files changed, 76 insertions(+), 16 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 80949b2..a0c6597 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,7 +11,7 @@ "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/Bücherwurm.dll", - "args": ["books.json"], + "args": ["books.json", "magazines.json"], "cwd": "${workspaceFolder}", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console "console": "integratedTerminal", diff --git a/Administration.cs b/Administration.cs index 329b5e5..44818ee 100644 --- a/Administration.cs +++ b/Administration.cs @@ -94,7 +94,7 @@ namespace Bücherwurm Console.WriteLine("Bitte geben Sie die ID des Buches an:"); var Id = int.Parse(Console.ReadLine()); Catalogue.Remove(Id); - Inventory.BookRemove(Id); + Inventory.ProductRemove(Id); } public void ListInventory() @@ -180,22 +180,30 @@ namespace Bücherwurm Console.WriteLine("Eine leere Zeile beendet die Aufnahme der entliehenen Exemplare."); var Input = ""; var LendList = new List(); + var VirtualList = new List(); do { - Console.WriteLine("Bitte Geben sie die Exemplar ID an:"); + Console.WriteLine("Bitte Geben sie die Produkt ID an:"); Input = Console.ReadLine(); if (Input != "") { - var ItemId = int.Parse(Input); - if (Inventory.isAvailable(ItemId) && !LendList.Contains(ItemId)) + var ProductId = int.Parse(Input); + if (Catalogue.LookupProduct(ProductId).LendType == LendTypeEnum.Physical) { - LendList.Add(ItemId); + if (Inventory.IsProductAvailable(ProductId).Count > 0 && !Inventory.IsProductAvailable(ProductId).TrueForAll(ItemId => LendList.Contains(ItemId))) + { + LendList.Add(Inventory.IsProductAvailable(ProductId).Find(ItemId => !LendList.Contains(ItemId))); + Console.WriteLine("ok"); + } + else + { + Console.WriteLine("Exemplar unbekannt oder bereits entliehen."); + } + } else + { + VirtualList.Add(ProductId); Console.WriteLine("ok"); } - else - { - Console.WriteLine("Exemplar unbekannt oder bereits entliehen."); - } } } while (Input != ""); Console.WriteLine("Bitte geben Sie den Kundennamen an:"); @@ -204,6 +212,13 @@ namespace Bücherwurm { int time = Catalogue.LookupProduct(Inventory.LookupItem(id).ProdId).LendTime; Lendings.Lend(id, Customer, time); + Inventory.MarkAsLended(id); + } + foreach (var prod in VirtualList) + { + int time = Catalogue.LookupProduct(prod).LendTime; + var linkDummy = string.Format("https://dies.ist.ein.downloadlink.fuer.{0}", prod); + Console.WriteLine("Dies ist ein {0} Tage gültiger Download-Link: {1}", time, linkDummy); } Console.WriteLine("Ausleihe erfolgreich!"); } @@ -215,6 +230,7 @@ namespace Bücherwurm if (Lendings.GetActiveLendings().Find(lending => lending.LendId == Returns) != null) { Lendings.Return(Returns); + Inventory.MarkAsAvailable(Lendings.GetActiveLendings().Find(lend => lend.LendId == Returns).LendItem); Console.WriteLine("Ausleihe erfolgreich zurückgegeben."); } else @@ -223,14 +239,30 @@ namespace Bücherwurm } } + public void MakeImport(string JsonTextBooks) + { + Catalogue.ImportBooks(JsonTextBooks); + foreach (var prod in Catalogue.GetProducts()) + { + if (prod.LendType == LendTypeEnum.Physical) + { + Inventory.Add(prod); + Inventory.Add(prod); + } + } + } + public void MakeImport(string JsonTextBooks, string JsonTextMagazines) { Catalogue.ImportBooks(JsonTextBooks); Catalogue.ImportMagazines(JsonTextMagazines); foreach (var prod in Catalogue.GetProducts()) { - Inventory.Add(prod); - Inventory.Add(prod); + if (prod.LendType == LendTypeEnum.Physical) + { + Inventory.Add(prod); + Inventory.Add(prod); + } } } } diff --git a/Catalogue.cs b/Catalogue.cs index 164ef9c..b0bf483 100644 --- a/Catalogue.cs +++ b/Catalogue.cs @@ -51,6 +51,7 @@ namespace Bücherwurm { var epaper = new EPaper(mag); epaper.OverwriteNullId(NextId); + ePapers.Add(epaper); NextId += 1; } Products.AddRange(new List(ePapers)); diff --git a/Inventory.cs b/Inventory.cs index 8fe153f..169ef39 100644 --- a/Inventory.cs +++ b/Inventory.cs @@ -30,7 +30,7 @@ namespace Bücherwurm InventoryList.RemoveAll(item => item.ItemId == Id); } - public void BookRemove(int ProdId) + public void ProductRemove(int ProdId) { InventoryList.RemoveAll(item => item.ProdId == ProdId); } @@ -45,14 +45,41 @@ namespace Bücherwurm return (InventoryList.Find(item => item.ItemId == Id) != null); } - public bool isAvailable(int Id) + public bool IsAvailable(int ItemId) { - return (InventoryList.Find(item => item.ItemId == Id && item.Status == StatusEnum.Available) != null); + return (InventoryList.Find(item => item.ItemId == ItemId && item.Status == StatusEnum.Available) != null); + } + + public List IsProductAvailable(int ProdId) + { + var items = InventoryList.FindAll(item => item.ProdId == ProdId && item.Status == StatusEnum.Available); + var ret = new List(); + foreach (var item in items) + { + ret.Add(item.ItemId); + } + if (ret.Count == 0) + { + return null; + } else + { + return ret; + } } public Item LookupItem(int ItemId) { return InventoryList.Find(item => ItemId == item.ItemId); } + + public void MarkAsLended(int ItemId) + { + InventoryList[InventoryList.FindIndex(item => item.ItemId == ItemId)].Status = StatusEnum.Lended; + } + + public void MarkAsAvailable(int ItemId) + { + InventoryList[InventoryList.FindIndex(item => item.ItemId == ItemId)].Status = StatusEnum.Available; + } } } \ No newline at end of file diff --git a/Program.cs b/Program.cs index adcf677..db04dcc 100644 --- a/Program.cs +++ b/Program.cs @@ -13,7 +13,7 @@ namespace Bücherwurm { Console.WriteLine("Versuche Bücher aus JSON Katalog von {0} zu importieren...", args[0]); string jsonString = File.ReadAllText(args[0]); - Admin.MakeImport(jsonString, ""); + Admin.MakeImport(jsonString); Console.WriteLine("Erfolg!"); } else if (args.Length == 2) {