public string ServeCustomer(StockController controller) { Thread.Sleep(Rnd.NextInt(5)); TShirt shirt = TShirtProvider.SelectRandomShirt(); string code = shirt.Code; bool custSells = Rnd.TrueWithProb(1.0 / 6.0); if (custSells) { int quantity = Rnd.NextInt(9) + 1; controller.BuyShirts(code, quantity); return($"Bought {quantity} of {shirt}"); } else { bool success = controller.TrySellShirt(code); if (success) { return($"Sold {shirt}"); } else { return($"Couldn't sell {shirt}: Out of stock"); } } }
public string ServeCustomer(StockController controller, LogTradesQueue bonusQueue) { Thread.Sleep(Rnd.NextInt(20)); TShirt shirt = TShirtProvider.SelectRandomShirt(); string code = shirt.Code; bool custSells = Rnd.TrueWithProb(1.0 / 6.0); if (custSells) { int quantity = Rnd.NextInt(9) + 1; controller.BuyShirts(code, quantity); bonusQueue.QueueTradeForLogging( new Trade(this, shirt, TradeType.Purchase, quantity)); return($"Bought {quantity} of {shirt}"); } else { bool success = controller.TrySellShirt(code); if (success) { bonusQueue.QueueTradeForLogging( new Trade(this, shirt, TradeType.Sale, 1)); return($"Sold {shirt}"); } else { return($"Couldn't sell {shirt}: Out of stock"); } } }