Ejemplo n.º 1
0
        public DiscountApplicationResult AddVoucher(IMayApplyDiscount voucher)
        {
            var applicationResult = _discountValidator.CanApplyDiscount(_vouchers, voucher);

            if (applicationResult.IsDiscountAllowed)
            {
                _vouchers.Add(voucher);
            }

            return(applicationResult);
        }
Ejemplo n.º 2
0
 public DiscountApplicationResult CanApplyDiscount(IEnumerable<IMayApplyDiscount> existingDiscounts, IMayApplyDiscount toAdd)
 {
     return IsTryingToAddAdditionalOfferVoucher(existingDiscounts, toAdd)
         ? DiscountApplicationResult.CreateFailed("Only a single offer voucher can be applied to a basket")
         : DiscountApplicationResult.CreateSuccess();
 }
Ejemplo n.º 3
0
 private static bool IsTryingToAddAdditionalOfferVoucher(IEnumerable<IMayApplyDiscount> existingDiscounts, IMayApplyDiscount toAdd)
 {
     return
         toAdd.GetDiscountType() == DiscountType.OfferVoucher
         && existingDiscounts.Any(discount => discount.GetDiscountType() == DiscountType.OfferVoucher);
 }