public DiscountApplicationResult AddVoucher(IMayApplyDiscount voucher) { var applicationResult = _discountValidator.CanApplyDiscount(_vouchers, voucher); if (applicationResult.IsDiscountAllowed) { _vouchers.Add(voucher); } return(applicationResult); }
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(); }
private static bool IsTryingToAddAdditionalOfferVoucher(IEnumerable<IMayApplyDiscount> existingDiscounts, IMayApplyDiscount toAdd) { return toAdd.GetDiscountType() == DiscountType.OfferVoucher && existingDiscounts.Any(discount => discount.GetDiscountType() == DiscountType.OfferVoucher); }