Lending works
This commit is contained in:
parent
8cd3906a32
commit
c0c12cba82
9 changed files with 32 additions and 17 deletions
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
|
@ -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
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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!");
|
||||
}
|
||||
|
||||
|
|
3
Book.cs
3
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;
|
||||
|
|
|
@ -24,6 +24,7 @@ namespace Bücherwurm
|
|||
{
|
||||
Ibook.OverwriteNullId(NextId);
|
||||
Ibook.Category = "book";
|
||||
Ibook.LendTime = 30;
|
||||
NextId += 1;
|
||||
}
|
||||
Products = new List<IProduct>(IntermediateBooks);
|
||||
|
@ -52,9 +53,9 @@ namespace Bücherwurm
|
|||
return Products.FindAll(prod => prod.Category == "book").Cast<Book>().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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,6 +8,8 @@ namespace Bücherwurm
|
|||
|
||||
string ImageLink { get; set;}
|
||||
|
||||
int LendTime {get; set;}
|
||||
|
||||
void OverwriteNullId(int id);
|
||||
}
|
||||
}
|
|
@ -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<Item> 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);
|
||||
}
|
||||
}
|
||||
}
|
4
Item.cs
4
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue