Undo in web app?

Undo in web app?

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


Gigatron posted on Monday, May 15, 2006

Shouldn't I be using BeginEdit(), ApplyEdit() and CancelEdit() in a web application if storing my objects in session variables?  For example, I have a parent and child.  The child is edited and the parent Save is called.  The business rules of the parent fail, but yet the child values have already been modified.  So what happens is, my form view control still shows the child values that the user entered even though the validation failed at the parent.  Isn't there a way to cancel(undo, rollback or whatever) the child objects to their orginal states? 

It's just I'm using Rocky's web example as a basis for learning and I don't see him using any undo capabilities.  I know, I could just reload the objects, but I want to do as much caching as I can to minimize trips to database.

Any suggestions on what I might be doing wrong?

RockfordLhotka replied on Monday, May 15, 2006

If you are using a Local data portal proxy, then you should use the same Clone() technique as in the Windows Forms chapter. BeginEdit() really isn't a solution here - because what you need is to get the object graph back to the state it was before trying to save it to the database.

Dim temp As Parent = _parent.Clone()
_parent = temp.Save()

(wrapped in Try..Catch of course)

Gigatron replied on Tuesday, May 16, 2006

Thanks, that works great Rocky.  I think I am getting confused on what really is a child object.  I have a 1 to 1 relationship between parent/child, there is no collection, so both are from BusinessBase.  I'm assuming the child should not set MarkAsChild(), as I can't delete the child from my parent.  Anyone have any examples of 1-to-1 parent/child relationships I could look at?

xal replied on Tuesday, May 16, 2006

In that case it doesn't necesarily have to be a child.... you can just count it as part of your object's data. (Whether it is required or not)
Then your sp would handle the insert / update / delete logic. Sometimes some relations feel like child objects, but they really aren't...

Andrés

Copyright (c) Marimer LLC