Example #1
0
        public decimal Total()
        {
            var groupedItems = Items
                               .GroupBy(i => i.Sku)
                               .Select(g => new
            {
                Sku   = g.Key,
                Count = g.Count()
            });

            decimal total = 0m;

            foreach (var line in groupedItems)
            {
                var specialOffer = _specialOffersRepository?.GetSpecialOfferBySku(line.Sku);
                if (specialOffer != null)
                {
                    total += line.Count / specialOffer.Quantity * specialOffer.OfferPrice + line.Count % specialOffer.Quantity * _itemsRepository.GetProductBySku(line.Sku).UnitPrice;
                }
                else
                {
                    total += line.Count * _itemsRepository.GetProductBySku(line.Sku).UnitPrice;
                }
            }
            return(total);
        }