Exemplo n.º 1
0
 public Trade(SalesPerson person, TShirt shirt, TradeType type, int quantitySold)
 {
     this.Person   = person;
     this.Shirt    = shirt;
     this.Type     = type;
     this.Quantity = quantitySold;
 }
Exemplo n.º 2
0
        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");
                }
            }
        }