public IList <IPriceValue> GetDiscountPriceList(IEnumerable <CatalogKey> catalogKeys, MarketId marketId, Currency currency)
        {
            var market = _marketService.GetMarket(marketId);

            if (market == null)
            {
                throw new ArgumentException(string.Format("market '{0}' does not exist", marketId));
            }

            var prices = catalogKeys.Select(x => PriceCalculationService.GetSalePrice(x.CatalogEntryCode, marketId, currency)).Where(x => x != null);

            return(GetDiscountPrices(prices.ToList(), market, currency));
        }
        private IEnumerable <DiscountedEntry> GetDiscountPrices(
            IEnumerable <ContentReference> entryLinks,
            IMarket market,
            Currency marketCurrency,
            ReferenceConverter referenceConverter)
        {
            if (entryLinks is null || market is null || marketCurrency.IsEmpty)
            {
                throw new ArgumentNullException(nameof(marketCurrency));
            }

            List <DiscountedEntry>       source     = new List <DiscountedEntry>();
            HashSet <string>             entryCodes = new HashSet <string>(entryLinks.Select(new Func <ContentReference, string>(referenceConverter.GetCode)));
            Dictionary <string, decimal> dictionary = new Dictionary <string, decimal>();

            foreach (RewardDescription rewardDescription in _promotionEngine.Evaluate(entryLinks, market, marketCurrency, RequestFulfillmentStatus.Fulfilled))
            {
                HashSet <string> usedCodes = new HashSet <string>();
                foreach (ILineItem lineItem in rewardDescription.Redemptions.Where(x => x.AffectedEntries != null).SelectMany(x => x.AffectedEntries.PriceEntries).Where(x => x != null).Select(x => x.ParentItem).Where(x => !usedCodes.Contains(x.Code)).Where(x => entryCodes.Contains(x.Code)))
                {
                    usedCodes.Add(lineItem.Code);
                    ContentReference entryLink       = referenceConverter.GetContentLink(lineItem.Code);
                    DiscountedEntry  discountedEntry = source.SingleOrDefault(x => x.EntryLink == entryLink);
                    if (discountedEntry == null)
                    {
                        discountedEntry = new DiscountedEntry(entryLink, new List <DiscountPrice>());
                        source.Add(discountedEntry);
                    }
                    if (dictionary.ContainsKey(lineItem.Code))
                    {
                        dictionary[lineItem.Code] -= rewardDescription.SavedAmount;
                    }
                    else
                    {
                        // lineItemCalculator.GetExtendedPrice(lineItem, marketCurrency).Amount;
                        decimal amount = PriceCalculationService.GetSalePrice(lineItem.Code, market.MarketId, marketCurrency).UnitPrice.Amount;
                        dictionary.Add(lineItem.Code, amount - rewardDescription.SavedAmount);
                    }
                    DiscountPrice discountPrice = new DiscountPrice((EntryPromotion)rewardDescription.Promotion, new Money(Math.Max(dictionary[lineItem.Code], 0M), marketCurrency), new Money(lineItem.PlacedPrice, marketCurrency));
                    discountedEntry.DiscountPrices.Add(discountPrice);
                }
            }
            return(source);
        }