Checking rules on dirty properties only

Checking rules on dirty properties only

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


triplea posted on Friday, January 30, 2009

I have a scenatio where one of my BOs (lets call it Customer) has got a number of validation rules. So when a customer is displayed on a form, the user needs to make sure everything is correct prior to saving, which is of course normal and works fine.

Now I need to provide a batch way of updating customer BOs. The user provides the customer identifier along with key/value pairs for properties who's values should be updated. What I would like to achieve is:

Is there any elegant way of achieving this by reusing my customer BO? Should I have a different BO? If so how would I achieve that?

Thanks!

ajj3085 replied on Friday, January 30, 2009

Well, that should happen normally as the user is modifying values.  Changing a property only runs rules tied to that property.

rsbaker0 replied on Friday, January 30, 2009

Maybe I'm missing something, but presumably you explicitly are calling ValidationRules.CheckRules() only for a new object. For an existing object, the individual rules aren't called unless the property for the rule is changed.

So, I would think this would work.

1. Load customer BO using identifier. Should be valid at this point since no rules have been checked.

2. Enumerate your key/value pairs and call property setter in BO for each present value (this will fire the rules for the properties as they are changed).

3. After setting all the changed properties, object will be valid or not.

triplea replied on Tuesday, February 03, 2009

Thanks both it was my mistake I was calling ValidationRules.CheckRules() on my base class for this app and forgot in the process... Silly user error!

Copyright (c) Marimer LLC