How to handle business rules where on property changes the value of another in Webforms

How to handle business rules where on property changes the value of another in Webforms

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


mtavares posted on Thursday, August 15, 2013

Here's my scenario, I have a boolean property that when checked should clear/set defaults (pulled from DB) for a number of other properties in the BO.  My application is a webforms app, so essentially all of the properties are set in a batch upon postback.  I have already seen this post regarding clearing dependent property values: http://forums.lhotka.net/forums/p/10903/50815.aspx#50815.  My question is this:  What is the best way to set up the rule so that order of the properties being set upon postback doesn't matter?

For example, I have a BO representing a contact.  The boolean field is whether the contact is an organization and when true, would clear the birthdate and set a default on the gender properties.  I would put a rule on the IsOrganization property that clears the other 2 fields. This would be fine if the Web UI is setting properties where IsOrganization is being set last, but what if the Web UI  sets the birthdate after the IsOrganization field was already set and the rules were run for it.  

I can see in a non-batch UI scenario, order wouldn't matter because the UI would update the dependent field controls accordingly before being saved. But in the Web UI everything is set at once and then saved before the UI is updated, so it seems to place this dependency on the UI side of making sure that the order of fields being set is correct.  Is there a better way to do this on the Business side so I don't have to worry about the order that data is being set in the UI?  I want the values that get set when IsOrganization is true to override anything that gets set on those dependent properties, and to take the dependent properties' values when IsOrganization is false.

Copyright (c) Marimer LLC