예제 #1
0
        public Dictionary <int, List <BuyingSet> > GetBuyingQuantityCombinations()
        {
            if (buyingQuantityCombinations == null)
            {
                buyingQuantityCombinations = new Dictionary <int, List <BuyingSet> >();

                for (var i = 1; i <= promotedBooks.Length; i++)
                {
                    var buyingSets   = new List <BuyingSet>();
                    var availableSet = promotedBooks.CombinationsNotRepeat(i);
                    foreach (var set in availableSet)
                    {
                        var newBuyingSet = new BuyingSet();
                        foreach (var item in set)
                        {
                            var newBuyingItem = new BuyingItem
                            {
                                BookId   = item,
                                Quantity = 1
                            };
                            newBuyingSet.Items.Add(newBuyingItem);
                        }
                        buyingSets.Add(newBuyingSet);
                    }
                    buyingQuantityCombinations.Add(i, buyingSets);
                }
            }
            return(buyingQuantityCombinations);
        }
예제 #2
0
 private void Action(BuyingSet buyingSet, bool negative)
 {
     foreach (var buyingItem in buyingSet.Items)
     {
         var item = Items.First(x => x.BookId == buyingItem.BookId);
         item.Quantity += (negative ? -1 : 1) * buyingItem.Quantity;
     }
 }
예제 #3
0
 public void GetOut(BuyingSet buyingSet)
 {
     Action(buyingSet, true);
 }
예제 #4
0
 public void PutIn(BuyingSet buyingSet)
 {
     Action(buyingSet, false);
 }