Add Business Rules for Business List Base child property

Add Business Rules for Business List Base child property

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


patelravij@gmail.com posted on Wednesday, May 16, 2012

Hi,

I Have object graphs with parent-child relationship. There are more than two children objects.

Parent object is BusinessBase object where other child objects are BusinessListBase objects.

Now I want to add validation for child objects that if not a single child objects is not added, Then parent objects should not allow to save.

Can anyone suggest how to add validation on BusinessListBaseProperty so it display error notification and CanSave property is  false?

Thanks in advance.

JonnyBee replied on Wednesday, May 16, 2012

How do you want to show the error to the user?

What type of UI do you use?

In general terms you need to decide on where to attach the broken rule:

In any case you should trigger the rule in the parent based on ChildChanged event like this

    protected override void OnChildChanged(ChildChangedEventArgs e)
    {
        base.OnChildChanged(e);
        
        // If attached to a property
        PropertyHasChanged(PropertyInfo);
        
        // or if attached at object level (this was introduced in Csla 4.2.0)
        CheckObjectRules();

    }

 

patelravij@gmail.com replied on Wednesday, May 16, 2012

Thanks for your suggestions.

I am using Silverlight 5 MVVM with CSLA 4.2 and Error message should be shown in PropertyStatus.

I understand your first suggestion using attached a property and how to shown in property status on UI next or before to Datagridview. But it fires every time if any property in child object is changed not only when any object is added or removed from list.

regarding to "on the list property in "root" (- in WindowsForms will be shown next to a list/datagridview)", Does CSLA allow add rules directly on BusinessListBase and validate it when property changed?

But  if attached at object level, How should it display propertystatus? Does it update UI ? As per my understanding,  CheckObjectRules() does not update UI(PropertyStatus). Please correct me if i am wrong. 

JonnyBee replied on Wednesday, May 16, 2012

Hi,

Well, you can inspect more details i ChildChangedEventArgs to restrict when the validation is triggered.

Yes, PropertyStatus does not (at current) support broken rules on object level.

Yes, you can add rules to ANY IPropertyInfo - but for child objects the validation rules are not automatically rechecked based on the ListChanged event.

Rules are normally triggered from PropertyHasChanged when the user edits a field (changes the value of the property and implicily called by SetProperty) or from BusinessRules.CheckRules().

 

Copyright (c) Marimer LLC