コード例 #1
0
        public decimal Apply(KeyValuePair <int, int> cartItem, decimal originalPrice)
        {
            log.Info("Checking Promotion");

            decimal price = cartItem.Value * originalPrice;

            if (null != _promotions && _promotions.ContainsKey(cartItem.Key))
            {
                IPromotion promotion = _promotions[cartItem.Key];

                switch (promotion.PromotionCode)
                {
                case var pcode when string.Equals(pcode, OfferedPromotions.AdditionalProductDiscount, System.StringComparison.OrdinalIgnoreCase):
                    _currentPromotion = new PromotionA(promotion);

                    break;

                case var pcode when string.Equals(pcode, OfferedPromotions.GroupPromotionalPrice, System.StringComparison.OrdinalIgnoreCase):
                    _currentPromotion = new PromotionB(promotion);

                    break;

                default:
                    break;
                }
                if (null != _currentPromotion)
                {
                    price = _currentPromotion.Calculate(cartItem.Value, originalPrice);
                }
            }

            return(price);
        }
 public ShoppingCart(IPromotionCalculator promotionCalculator)
 {
     this.promotionCalculator = promotionCalculator ?? throw new ArgumentNullException(nameof(promotionCalculator));
     ShoppingCartId           = GetCartId();
 }
コード例 #3
0
 public PromotionalPrice(IStoreRepository storeRepository)
 {
     _promotions       = storeRepository.GetPromotions();
     _currentPromotion = null;
 }