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); }
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; } }
public void GetOut(BuyingSet buyingSet) { Action(buyingSet, true); }
public void PutIn(BuyingSet buyingSet) { Action(buyingSet, false); }