public void DisplayReport(SalesPerson[] people)
 {
     Console.WriteLine();
     Console.WriteLine("Transactions by salesperson:");
     foreach (var person in people)
     {
         var sales = _salesByPerson.GetOrAdd(person, 0);
         var purchases = _purchasesByPerson.GetOrAdd(person, 0);
         Console.WriteLine("{0,15} sold {1,3:n0}, bought {2,3:n0} items, total {3:n0}", person.Name, sales, purchases, sales + purchases);
     }
 }
 public bool TrySellItem(SalesPerson person, string item)
 {
     var success = false;
     _stock.AddOrUpdate(item,
         itemName => { success = false; return 0; },
         (itemName, value) =>
         {
             if (value == 0)
             {
                 success = false;
                 return 0;
             }
             success = true;
             return value - 1;
         });
     if (success)
     {
         Interlocked.Increment(ref _totalQuantitySold);
         _toDoQueue.AddTrade(new Trade(person, 1));
     }
     return success;
 }
        public bool TrySellItem(SalesPerson person, string item)
        {
            var success = false;

            _stock.AddOrUpdate(item,
                               itemName => { success = false; return(0); },
                               (itemName, value) =>
            {
                if (value == 0)
                {
                    success = false;
                    return(0);
                }
                success = true;
                return(value - 1);
            });
            if (success)
            {
                Interlocked.Increment(ref _totalQuantitySold);
                _toDoQueue.AddTrade(new Trade(person, 1));
            }
            return(success);
        }
 public void BuyStock(SalesPerson person, string item, int quantity)
 {
     _stock.AddOrUpdate(item, quantity, (key, value) => value + quantity);
     Interlocked.Add(ref _totalQuantityBought, quantity);
     _toDoQueue.AddTrade(new Trade(person, -quantity));
 }
예제 #5
0
 public void BuyStock(SalesPerson person, string item, int quantity)
 {
     _stock.AddOrUpdate(item, quantity, (key, oldValue) => oldValue + quantity);
     Interlocked.Add(ref _totalQuantityBought, quantity);
     _toDoQueue.AddTrade(new Trade(person, -quantity));
 }