private List<IPaymentRule> findMatchingPaymentRules(Supplier supplier, Customer customer, BookingType bookingType) { IReadOnlyList<IPaymentRule> suppliersPaymentRules = supplier.PaymentRules; List<IPaymentRule> paymentRulesForCustomer = findPaymentRulesForCustomer(suppliersPaymentRules, customer); if (paymentRulesForCustomer.Count == 0) { Customer anyCustomer = customerController.findAnyCustomer(); paymentRulesForCustomer = findPaymentRulesForCustomer(suppliersPaymentRules, anyCustomer); } List<IPaymentRule> paymentRulesForBookingType = findPaymentRulesForBookingType(paymentRulesForCustomer, bookingType); if (paymentRulesForBookingType.Count == 0) { paymentRulesForBookingType = findPaymentRulesForBookingType(paymentRulesForCustomer, BookingType.Undefined); } return paymentRulesForBookingType; }
private List<IPaymentRule> findPaymentRulesForCustomer(IReadOnlyList<IPaymentRule> suppliersPaymentRules, Customer customer) { List<IPaymentRule> paymentRulesForCustomer = new List<IPaymentRule>(); foreach (IPaymentRule paymentRule in suppliersPaymentRules) { if (((Customer)paymentRule.Customer)._customerEntity == customer._customerEntity) { paymentRulesForCustomer.Add(paymentRule); } } return paymentRulesForCustomer; }