Design Question on validation

Design Question on validation

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


Joffies posted on Friday, August 22, 2008

I have the following classes:

Award (BusinessBase) - Parent
AwardVesting (BusinessBase) - Child
AwardVestings (BusinessListbase) - ChildCollection

My child object has a property/field called Percentage. Within the collection the sum of all percentages may never exceed 100%.

I currently have validation method within the AwardVestings which checks that new entries added values never exceed 100%. This works fine when adding new children to the children collection.

The childcollection however is bound to a grid and the will be allowed to change the Percentage and therefore validation needs to take place when the childcollection has changed.

How can I enfore validation on a property of a collection for existing items within the collection incase the values (percentage) change?

Thanks for any pointers

richardb replied on Friday, August 22, 2008

There may be an event that's raised back to the gride as a child is changed, and you might then be able to respond to that event and force a revalidation on the parent object at that point.  I'm a bit rusty here on that but HTH.

sergeyb replied on Friday, August 22, 2008

Here is one suggestion.

 

If you want the Award to be aware of the percentage rule violation, I would create a property for an award, like TotalPercentage (public get) and put a rule on it.  Then when child.Percentage changes, call Award to re-calc and validate the TotalPercentage property, as in ((AwardVerstings)this.Parent).ParentAward.SetAndValidateTotalPercentage().  Public get of TotalPercentage would return the sum of children’s percentages.

This way the user can easily see total percentage as well.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

Magenic ®

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: Joffies [mailto:cslanet@lhotka.net]
Sent: Friday, August 22, 2008 9:41 AM
To: Sergey Barskiy
Subject: [CSLA .NET] Design Question on validation

 

I have the following classes:

Award (BusinessBase) - Parent
AwardVesting (BusinessBase) - Child
AwardVestings (BusinessListbase) - ChildCollection

My child object has a property/field called Percentage. Within the collection the sum of all percentages may never exceed 100%.

I currently have validation method within the AwardVestings which checks that new entries added values never exceed 100%. This works fine when adding new children to the children collection.

The childcollection however is bound to a grid and the will be allowed to change the Percentage and therefore validation needs to take place when the childcollection has changed.

How can I enfore validation on a property of a collection for existing items within the collection incase the values (percentage) change?

Thanks for any pointers



Copyright (c) Marimer LLC