Buecherwurm/Inventory.cs

85 lines
2.2 KiB
C#
Raw Normal View History

2020-04-23 12:47:50 +00:00
using System.Collections.Generic;
namespace Bücherwurm
{
class Inventory
{
private List<Item> InventoryList {get; set;}
2020-04-23 13:44:38 +00:00
private int NextId {get; set;}
2020-04-23 12:47:50 +00:00
public Inventory(){
InventoryList = new List<Item>();
2020-04-27 09:26:45 +00:00
NextId = 1;
2020-04-23 12:47:50 +00:00
}
2020-04-27 14:14:20 +00:00
public void Add(IProduct Book)
2020-04-23 12:47:50 +00:00
{
2020-04-27 14:14:20 +00:00
InventoryList.Add(new Item(NextId, Book.ProductId));
2020-04-27 09:26:45 +00:00
NextId = NextId + 1;
2020-04-23 12:47:50 +00:00
}
2020-04-24 13:54:17 +00:00
public void Add(int BookId)
{
InventoryList.Add(new Item(NextId, BookId));
2020-04-27 09:26:45 +00:00
NextId = NextId + 1;
2020-04-24 13:54:17 +00:00
}
2020-04-23 12:47:50 +00:00
public void Remove(int Id)
{
2020-04-23 13:44:38 +00:00
InventoryList.RemoveAll(item => item.ItemId == Id);
2020-04-23 12:47:50 +00:00
}
2020-04-24 13:54:17 +00:00
public void ProductRemove(int ProdId)
2020-04-24 13:54:17 +00:00
{
2020-04-28 08:54:22 +00:00
InventoryList.RemoveAll(item => item.ProdId == ProdId);
2020-04-24 13:54:17 +00:00
}
public List<Item> GetInventory()
{
return InventoryList;
}
public bool IsInInventory(int Id)
{
return (InventoryList.Find(item => item.ItemId == Id) != null);
}
public bool IsAvailable(int ItemId)
2020-04-24 13:54:17 +00:00
{
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;
}
2020-04-24 13:54:17 +00:00
}
2020-04-28 08:54:22 +00:00
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;
}
2020-04-23 12:47:50 +00:00
}
}