public PromotionResult ApplyPromotion(IEnumerable <IOrderItem> orderItems)
        {
            var result = PromotionResult.Failure();

            var skuOrderItem = GetFirstApplicableOrderItem(orderItems);

            if (skuOrderItem != null)
            {
                var fixedPriceMultiplier = skuOrderItem.Count / _count;
                var fullPriceMultiplier  = skuOrderItem.Count % _count;
                var adjustmentAmount     = skuOrderItem.Amount - (fixedPriceMultiplier * _fixedPrice + fullPriceMultiplier * skuOrderItem.SKU.UnitPrice);
                var adjustmentOrderItem  = new PromotionAdjustmentOrderItem(-adjustmentAmount);
                return(PromotionResult.Success(adjustmentOrderItem, new ISKU[] { skuOrderItem.SKU }));
            }
            return(result);
        }
Пример #2
0
        public PromotionResult ApplyPromotion(IEnumerable <IOrderItem> orderItems)
        {  // assumption: max 1 order item per SKU
            var result = PromotionResult.Failure();

            var relevantOrderItems = orderItems.OfType <ISKUOrderItem>()
                                     .Where(x => _skuIdCombination.Contains(x.SKU.ID))
                                     .ToList();

            if (relevantOrderItems.Count == _skuIdCombination.Count)
            {
                var combinedUnitPriceBeforeAdjustment = relevantOrderItems.Sum(x => x.SKU.UnitPrice);
                var adjustment     = combinedUnitPriceBeforeAdjustment - _fixedPrice;
                var adjustmentItem = new PromotionAdjustmentOrderItem(-adjustment);
                return(PromotionResult.Success(adjustmentItem, relevantOrderItems.Select(x => x.SKU)));
            }
            return(result);
        }
Пример #3
0
        static void Main(string[] args)

        {
            IPromotion promotion = null;

            promotion = new Promotion1();

            PromotionResult promotionResult = new PromotionResult(promotion);

            promotionResult.Items.Add(new ItemA()

            {
                NoOfItems = 3,

                Cost = 50
            });

            promotionResult.Items.Add(new ItemB()

            {
                NoOfItems = 2,

                Cost = 30
            });

            promotionResult.Items.Add(new ItemC()

            {
                NoOfItems = 2,

                Cost = 20
            });

            promotionResult.Items.Add(new ItemD()

            {
                NoOfItems = 2,

                Cost = 15
            });

            Console.WriteLine(promotionResult.Calculate());

            Console.ReadLine();
        }