internal void Sell(Agent seller, Stack goodsToSell, double pricePerUnit) { var agentPurchasables = purchasables .FirstOrDefault(o => o.SellersNumber == seller.AgentNumber && o.Stack.Good == goodsToSell.Good && o.PricePerUnit == pricePerUnit); if (agentPurchasables == null) { purchasables.Add(new Purchasable( seller.AgentNumber, pricePerUnit, goodsToSell)); } else { var newStack = new Stack( goodsToSell.Good, goodsToSell.Quantity + agentPurchasables.Stack.Quantity); var newP = new Purchasable( seller.AgentNumber, pricePerUnit, newStack); } }
public void Purchase(Agent buyer, Agent seller, Purchasable purchasable, double quantity) { var p = this.purchasables .Where(o => o == purchasable) .First(); p.Purchase(buyer, seller, quantity); if (p.Stack.Quantity <= 0.0) { this.purchasables.Remove(p); } }