CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Business rules execution on complex properties

rated by 0 users
Answered (Verified) This post has 2 verified answers | 4 Replies | 2 Followers

Not Ranked
11 Posts
Kirby posted on Tue, Mar 29 2011 6:05 AM

Hi,

I have a BusinessObject called Scale having multiple properties of type Weight (e.g. ReferenceWeight, DisplayWeight, StandardWeight, etc.)

The Weight BusinessObject itself has a WeightUnit and a WeightValue.

Now I want to Create a BusinessRule calculating a DisplayWeight when the WeightUnit or the WeightValue of the ReferenceWeight is updated. The DisplayWeight shhould only be updated when a property of the ReferenceWeight has been changed. If the properties of other Weight properties are changed the rules needs not to be called (must not be called).

I tried to mark the Weight BusinessObject as child and call the rule in OnChildChange:

 

 protected override void OnChildChanged(Csla.Core.ChildChangedEventArgs e)
{
 
base.OnChildChanged(e);
  BusinessRules.CheckRules(DisplayWeightProperty);
}

 

But in this case the rules is executed each time when one of the weight property has been changed. Moreover because I'm changing the DisplayWeight (whichis a Wight itself) the rules is called recursively...

What is the best way to implement a Business rule which depends on the property of a property (a subproperty)?

Thanks

Kirby

 

Answered (Verified) Verified Answer

Top 10 Contributor
3,922 Posts
Answered (Verified) Andy replied on Tue, Mar 29 2011 5:25 PM
Verified by Kirby

Check the parameter e, you should be able to see which property changed.

Not Ranked
11 Posts
Answered (Verified) Kirby replied on Thu, Mar 31 2011 4:50 PM
Verified by Kirby

Some investigations later...

e.ChildObject and the my ReferenceWeight are the same objects when a property on ReferenceWeight changes... So a simple reference comparison does the trick! 

protected override void OnChildChanged(Csla.Core.ChildChangedEventArgs e)
{
   base.OnChildChanged(e);
 
   if (e.ChildObject == this.CurrentScaleWeight && 
       (e.PropertyChangedArgs.PropertyName == "Unit" || e.PropertyChangedArgs.PropertyName == "Value")
   )
   {
      BusinessRules.CheckRules(CurrentScaleWeightProperty);
   }
}

Andy - you were right with your answer of corse!

Cheers

Kirby

All Replies

Top 10 Contributor
3,922 Posts
Answered (Verified) Andy replied on Tue, Mar 29 2011 5:25 PM
Verified by Kirby

Check the parameter e, you should be able to see which property changed.

Not Ranked
11 Posts
Kirby replied on Thu, Mar 31 2011 3:49 PM

Hi,

in "Csla.Core.ChildChangedEventArgs e" I can see the name of tha parameter changed (on the child object). I my case I see that WeightUnit or WeightValue was changed but I do not know whether it was a WeightValue of DisplayWeight or ReferenceWeight! If can check the ChildObject on e but that also gives me just an Weight and I have no idea what kind of weight.

Any ideas?

Kirby

Not Ranked
11 Posts
Answered (Verified) Kirby replied on Thu, Mar 31 2011 4:50 PM
Verified by Kirby

Some investigations later...

e.ChildObject and the my ReferenceWeight are the same objects when a property on ReferenceWeight changes... So a simple reference comparison does the trick! 

protected override void OnChildChanged(Csla.Core.ChildChangedEventArgs e)
{
   base.OnChildChanged(e);
 
   if (e.ChildObject == this.CurrentScaleWeight && 
       (e.PropertyChangedArgs.PropertyName == "Unit" || e.PropertyChangedArgs.PropertyName == "Value")
   )
   {
      BusinessRules.CheckRules(CurrentScaleWeightProperty);
   }
}

Andy - you were right with your answer of corse!

Cheers

Kirby

Top 500 Contributor
30 Posts

I need to do a similar thing except my child property is a list.

In this case, PropertyChangedArgs is null in the ChildChangedEventArgs param. How can I easily find the property that matches the ChildObject that has changed?

Note that I am implementing this in my own BusinessBase class derived from Csla.BusinessBase. So I can't simply do something like e.ChildObject == this.CurrentScaleWeight, like this example.

Any suggestions would be greatly appreciated.

Page 1 of 1 (5 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems