Business rule - check of sibling

Business rule - check of sibling

Old forum URL: forums.lhotka.net/forums/t/6963.aspx


rlriggs posted on Monday, May 18, 2009

This seems basic and probably is but I'm missing it.

I have an editable root collection of a single client's multiple phone numbers. One of the properties of the editable child is called 'IsPrimary' to indicate it's the main number.

When a user adds a new number (to the collection object) and tries to check 'IsPrimary' (for the editable object), I need to lookup other sibling values to see if one is already marked as a primary and let the user know they can only mark one number as primary.

I can't reference the parent collection to loop through without generating errors (and I know this violates some design rules)

Any examples you can point me to? Should I use a command object to do the lookup?

ajj3085 replied on Tuesday, May 19, 2009

First... are you talking about a ERLB? I'd be suprised. I used to have an internal method called CheckRules on the child, and the containing list could listen for list changed events, and asked every child to check its rules... EXCEPT the child causing the change event (if there was one).

What I prefer to do now though is have the rule on the parent... so the Numbers collection is likely contained by the Contact parent (which is the root). Contact then has the rule and checks out all the children.. that means the parent knows about it's children, but because it's all part of the same use case, I feel its a fair trade off.

The advantage of the first method is that each row in the grid can have an error indicator, but the second method keeps all the code in one place (the root). It also makes more sense to me, since the child is only concerned about itself, but the root is concerned with collection itself. You could also reuse the PhoneNumber in another use case, if appropriate.

Copyright (c) Marimer LLC