finish implementation of electronic media
This commit is contained in:
parent
48bb08bd88
commit
7cd70212a4
5 changed files with 76 additions and 16 deletions
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -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",
|
||||
|
|
|
@ -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<int>();
|
||||
var VirtualList = new List<int>();
|
||||
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");
|
||||
}
|
||||
}
|
||||
} 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,15 +239,31 @@ 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())
|
||||
{
|
||||
if (prod.LendType == LendTypeEnum.Physical)
|
||||
{
|
||||
Inventory.Add(prod);
|
||||
Inventory.Add(prod);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -51,6 +51,7 @@ namespace Bücherwurm
|
|||
{
|
||||
var epaper = new EPaper(mag);
|
||||
epaper.OverwriteNullId(NextId);
|
||||
ePapers.Add(epaper);
|
||||
NextId += 1;
|
||||
}
|
||||
Products.AddRange(new List<IProduct>(ePapers));
|
||||
|
|
33
Inventory.cs
33
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<int> IsProductAvailable(int ProdId)
|
||||
{
|
||||
var items = InventoryList.FindAll(item => item.ProdId == ProdId && item.Status == StatusEnum.Available);
|
||||
var ret = new List<int>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue