Buecherwurm/Inventory.cs

85 lines
No EOL
2.2 KiB
C#

using System.Collections.Generic;
namespace Bücherwurm
{
class Inventory
{
private List<Item> InventoryList {get; set;}
private int NextId {get; set;}
public Inventory(){
InventoryList = new List<Item>();
NextId = 1;
}
public void Add(IProduct Book)
{
InventoryList.Add(new Item(NextId, Book.ProductId));
NextId = NextId + 1;
}
public void Add(int BookId)
{
InventoryList.Add(new Item(NextId, BookId));
NextId = NextId + 1;
}
public void Remove(int Id)
{
InventoryList.RemoveAll(item => item.ItemId == Id);
}
public void ProductRemove(int ProdId)
{
InventoryList.RemoveAll(item => item.ProdId == ProdId);
}
public List<Item> GetInventory()
{
return InventoryList;
}
public bool IsInInventory(int Id)
{
return (InventoryList.Find(item => item.ItemId == Id) != null);
}
public bool IsAvailable(int ItemId)
{
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;
}
}
}