Пример #1
0
        public string ServeCustomer(StockController controller, LogTradesQueue tradesQueue)
        {
            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);
                tradesQueue.QueueTradeForLogging(
                    new Trade(this, shirt, TradeType.Purchase, quantity));
                return($"Bought {quantity} of {shirt}");
            }
            else
            {
                bool success = controller.TrySellShirt(code);
                if (success)
                {
                    tradesQueue.QueueTradeForLogging(
                        new Trade(this, shirt, TradeType.Sale, 1));
                    return($"Sold {shirt}");
                }
                else
                {
                    return($"Couldn't sell {shirt}: Out of stock");
                }
            }
        }
Пример #2
0
 public Trade(SalesPerson person, TShirt shirt, TradeType type, int quantitySold)
 {
     this.Person   = person;
     this.Shirt    = shirt;
     this.Type     = type;
     this.Quantity = quantitySold;
 }