Can I Save saveable child objects and skip invalid ones?

Can I Save saveable child objects and skip invalid ones?

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


chrisb2 posted on Tuesday, April 29, 2008

I have a web page that is a questionnaire.  Each question is an editable child and the list of questions is an editable child list which in turn is in an editable root parent Questionnaire object.  The problem is that if a user has just one invalid question response, he cannot save any of them.  If he answers 15 questions and clicks Save, I cannot call questionnaire.Save() because questionnaire is not valid since it has an invalid child..  So no responses are saved.  If he doesn't know better and logs off thinking he can come back later to fix the bad ones, he looses all his work.  This is a bad situation.  I wouldn't mind if he looses the invalid answers, but I want to be able to save saveable children.

Has anybody else dealt with this?

I'm considering modifying the CSLA framework to support a SaveValidChildren(), but I'm not sure how to do that either.  In some situations that should not be used because it could lead to inconsistant data.

 

Thanks,

Chris

 

robert_m replied on Tuesday, April 29, 2008

How about changing your validation logic a bit so that an incorrectly answered question doesn't get marked invalid ?

Instead you could introduce a bool property (into Question class) indicating whether a question is correctly answered or not.

DocJames replied on Tuesday, April 29, 2008

I'm building a ClickOnce application with a DataPortal.

To only save valid children, I created a "GetListToSave" method in my List class which returns a new List containing only the deleted and saveable child object.

I then save the new List object.

On my List class I also have a "SetListAfterSave" method which accepts the saved List. I then removed deleted children and update the saved children (remember .Clone when updating the children).

This way I only send the deleted and updated children to the DataPortal.

Let me know if you are interested in the source code.

Jimmy

ajj3085 replied on Tuesday, April 29, 2008

Hi,

You should probably change your rules to be Warning rules instead of Error rules.  Warnings will allow you to save the instance fine.  You'll also have to have a way to move the questionaire from an "incomplete" state to a completed one as well.  Incomplete questionaires would have broken Warning rules.   Transitioning to completed would require that there are no broken rules, warning or otherwise.

HTH
Andy

Copyright (c) Marimer LLC