CSLA .NET

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

Execute Business rule on child object When Parent property has change.

rated by 0 users
Answered (Verified) This post has 1 verified answer | 5 Replies | 2 Followers

Not Ranked
9 Posts
Marsh posted on Mon, Mar 12 2012 3:02 AM

I have parent root(Mater) object as BusinessBase which has BusinessListBase(ChildList) object as a child.

Parent (BusinessBase)

    - Child List (BusinessListBase)

                - Child (BusinessBase)

I have a custom business rule implemented in child object (BusinessBase of ChildList), which depends on parent root(Mater) property. Now when parent root(Mater) property is changed, how to notify child object?

There is override method OnChildChanged which fires when any child property changed. Is there any way to fires custom rules on child object and show property status when parent property has been changed?

Answered (Verified) Verified Answer

Top 10 Contributor
1,772 Posts
Verified by Marsh

you can extend the child object with a "CheckAllRules" that notify UI of changes like this:

    public void CheckAllRules()
    {
      var propertyNames = BusinessRules.CheckRules();
      if (ApplicationContext.PropertyChangedMode == ApplicationContext.PropertyChangedModes.Windows)
        OnPropertyChanged(property);
      else
        foreach (var name in propertyNames)
          OnPropertyChanged(name);
    }

 And call this in from the PropertyHasChanged in the root object.

 

Jonny Bekkum, Norway CslaContrib Coordinator

All Replies

Top 10 Contributor
1,772 Posts

You can override PropertyHasChanged in parent object and rerun rules for child objects when that specific property has changed.

PropertyHasChanged will only be called when property content has changed.

Jonny Bekkum, Norway CslaContrib Coordinator

Not Ranked
9 Posts
Marsh replied on Mon, Mar 12 2012 4:05 AM

Thanks JonnyBee for prompt reply


I have override PropertyHasChanged in parent object. But how can I check business rules for each child in ChildList?
I have tried below two methods for check business rules.
BusinessRules.CheckRules() and  BusinessRules.CheckObjectRules(). But it does not fire business rules for child objects and does not update property status.


So can you please guide me how to rerun business rules for each child in Child List so than custom business rules execute and property status is updated?

Top 10 Contributor
1,772 Posts
Verified by Marsh

you can extend the child object with a "CheckAllRules" that notify UI of changes like this:

    public void CheckAllRules()
    {
      var propertyNames = BusinessRules.CheckRules();
      if (ApplicationContext.PropertyChangedMode == ApplicationContext.PropertyChangedModes.Windows)
        OnPropertyChanged(property);
      else
        foreach (var name in propertyNames)
          OnPropertyChanged(name);
    }

 And call this in from the PropertyHasChanged in the root object.

 

Jonny Bekkum, Norway CslaContrib Coordinator

Not Ranked
9 Posts
Marsh replied on Wed, Mar 14 2012 12:45 AM

I have tried your sugestion and Its worsk. Thanks a lot....

Not Ranked
1 Posts

Shah,

I have an interface IGrandChildList that all lists implement to expose the Parent and override the SetParent method of the child object. I thenadd a handler OnParentChanged that will allow me to execute my rules.

Protected Overrides Sub SetParent(parent As Csla.Core.IParent)
            AddHandler DirectCast(parent, IGrandChildList).GetParent.PropertyChanged, AddressOf OnParentChanged
            MyBase.SetParent(parent)
End Sub
Protected Overridable Sub OnParentChanged(sender As Object, e As System.ComponentModel.PropertyChangedEventArgs)
            ' Check Rules here

End Sub

Page 1 of 1 (6 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