Ejemplo n.º 1
0
        public ConditionDiscount Xor(ConditionDiscount d, bool decide)
        {
            Func <ShoppingBasket, DiscountOfProducts> f = new Func <ShoppingBasket, DiscountOfProducts>
                                                              ((ShoppingBasket shoppingBasket) => XorHelper(shoppingBasket, this, d, decide)
                                                              );

            return(new ConditionDiscount(new DiscountCalculator(f)));
        }
Ejemplo n.º 2
0
        public ConditionDiscount Or(IRule additionalRule)
        {
            ConditionDiscount discount = new ConditionDiscount(new DiscountCalculator(base.Calc));
            IRule             orRule   = Rule.OrTwoRules(_rule, additionalRule);

            discount.AddRule(orRule);
            return(discount);
        }
Ejemplo n.º 3
0
        public DiscountOfProducts XorHelper(ShoppingBasket shoppingBasket, ConditionDiscount d1, ConditionDiscount d2, bool decide)
        {
            bool available1 = d1.Available(shoppingBasket);
            bool available2 = d2.Available(shoppingBasket);

            //if both discounts are available decide by the 'decide' value
            if (available1 && available2)
            {
                if (decide)
                {
                    return(d1.Calc.CalcDiscount(shoppingBasket));
                }
                else
                {
                    return(d2.Calc.CalcDiscount(shoppingBasket));
                }
            }
            else if (available1)
            {
                return(d1.Calc.CalcDiscount(shoppingBasket));
            }
            else
            {
                return(d2.ApplyDiscounts(shoppingBasket));
            }
        }