How check business rules and update the error list when an Item is added to a collection

How check business rules and update the error list when an Item is added to a collection

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


olawal posted on Monday, December 05, 2011

Does anyone have any code sampels that do not rely on  OnPropertyChanged  for checking the business rules and passing errors back the the UI (2 tier application)

right now the code uses a handler and activates a callback action to acomplish this but it only works sporadically.  ie :

Protected Overrides Sub OnCollectionChanged(e As System.Collections.Specialized.NotifyCollectionChangedEventArgs)
thanks in advance

-ola

RockfordLhotka replied on Tuesday, December 06, 2011

Do you want the validation error to appear as part of the parent object that contains the collection, or the child object(s) in the collection?

Either way, you should consider overriding OnChildChanged in the parent object that contains the collection, and that's where you should either trigger the rules in the parent, or trigger the rules in the child that was changed.

olawal replied on Monday, January 09, 2012

I never got an email to know that you had answered thsi question along with the fact that I got pulled into another project and funally just got back to working on this problem.

You are correct in that I do want the error to to be part of the parent object that contains the collection.  I don't know if this will work though since there are no postbacks with the way the code we have is wirtten  its  constits of alot of jquery and ajax elements.

thanks again

 

 

RockfordLhotka replied on Monday, January 09, 2012

I discuss this in the Using CSLA 4 ebook series.

The short answer is that in the parent object you override OnChildChanged, and that way you know that a child object has changed so you can execute appropriate rules in the parent object by calling BusinessRules.CheckRules.

I don't know how this will work with ajax callbacks. If the state available on the web/app server isn't current, clearly you can't run any rules at that location. So you'll have to implement your solution such that the web/app server has the current state at the point you expect the rules to run.

olawal replied on Tuesday, January 10, 2012

Ok you basically confirmed what I thought

We found a work arround using SQL to create a specific error message , I then catch that error and display the specific error  based on the content in the message.  A bit ugly but it works well in this scenario.  The only thing I dislike is I could not grab error message constants from my business rule withoute fully instantiaing it Argh!

thanks for the fast feedback

-ola

Copyright (c) Marimer LLC