public class InventoryManager
private readonly List<InventoryItem> inventory = new List<InventoryItem>();
private readonly List<InventoryItem> itemsSold = new List<InventoryItem>();
public event Action<string> ItemSoldOut;
public event Action<string> ItemBecameAvailable;
public float AverageProfit => this.inventory.Sum(i => i.ProfitPerItem) / this.inventory.Count();
public float ProfitLastHour { get; private set; }
public void AddToStock(string name, int count)
var item = this.inventory.First(i => i.Name == name);
item.StockCount += count;
if (item.StockCount == count)
this.ItemBecameAvailable(name);
public void SellItem(string name, int count)
var item = this.inventory.First(i => i.Name == name);
item.StockCount -= count;
if (item.StockCount == 0)
item.Date = DateTime.Now;
this.itemsSold.Add(item);
this.ProfitLastHour = this.itemsSold
.Where(i => i.Date >= DateTime.Now.AddHours(-1))
.Sum(i => i.ProfitPerItem * i.StockCount);
public string Name { get; set; }
public float Price { get; set; }
public float Cost { get; set; }
public int StockCount { get; set; }
public DateTime Date { get; set; }
public float ProfitPerItem => this.Price - this.Cost;