Editable Child Collection: Total Column1 Must Equal Total Column2

Editable Child Collection: Total Column1 Must Equal Total Column2

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


superkuton posted on Monday, December 28, 2009

I have the following BO:


Journal (Editable Root Object)
----------------
ID
<other properties>

JournalDetail(Editable Child Object)
----------------
ID
JournalID (FK => Journal.ID)
DebitAmount
CreditAmount

JournalDetailList(Editable Child Collection, of JournalDetail)
-----------------


A business rule requires that the total DebitAmount must equal the total CreditAmount in the JournalDetailList (collection).

How do I add the business rule?

ajj3085 replied on Tuesday, December 29, 2009

I would put the rule in Journal.  JournalDetail could have a Total property.. the collection can also have such a property (likely internal, since you can't bind to properties on collections).  Your Journal would also have this Total property.  It just returns whatever the collection's Total is.  You then tie the rule to that property, and listen for ChildChanged events where you call your validation rule and then raise a property changed.

I think that should work.. I do similar things for a Free of Charge order.. where the order's total must equal $0.00.

superkuton replied on Tuesday, December 29, 2009

Thanks for the suggestion ajj3085.

I am just new to csla, can you help me with some sample code please?

Thank you.

Copyright (c) Marimer LLC