Quantcast
Channel: CSLA .NET
Viewing all articles
Browse latest Browse all 764

Adding a chained rule using a property on another Business Object

$
0
0

I have a BO called Payment.

When a Customer makes a payment, I need to require that Customer to have a BillingAddress set, if it is an account payment.

However, I'm not sure how to do this in practice. What I have so far is shown below - it is throwing "given key not present in the dictionary". I can understand why. Really I just don't know if this is possible.

CODE:

private class ValidCustomerBusinessAddressRequiredForAccountPayments : BusinessRule

        {

            private readonly IBusinessRule _addressRequiredRule;

            private readonly IBusinessRule _addressCompletedRule;

            public ValidCustomerBusinessAddressRequiredForAccountPayments()

                : base(MethodProperty)

            {

                InputProperties = new List<IPropertyInfo> { MethodProperty };

                _addressRequiredRule = new Required(Customer.BillingAddressProperty);

                _addressCompletedRule = new FullAddressRule(Customer.BillingAddressProperty);

            }

            protected override void Execute(RuleContext context)

            {

                var target = (Payment)context.Target;

                var method = target.Method;

                var customer = Customer.Get(target.PrimaryContactId);

                if (customer != null && method == PaymentMethod.Account)

                {

                    context.ExecuteRule(_addressRequiredRule); // throws exception

                    context.ExecuteRule(_addressCompletedRule);

                }

            }

        }


Viewing all articles
Browse latest Browse all 764

Trending Articles