Exception on Save() ERLB

Exception on Save() ERLB

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


esteban404 posted on Tuesday, February 10, 2009

Using CSLA 3.0.5 I have the ERLB working fine in a Windows Form application. If a rule is violated which prevents a save, the exception bubbles up from BusinessBase and prompts the user: "Object is not valid and cannot be saved. Do you want to correct the value?". If the user selects "NO", the application crashes with an unhandled exception.

If they select "NO" it's probably because they need to chase down some information and come back to it later. So I need to catch their response. I have overridden Save() in the BO:
public override Defect Save()
{
if (this.IsValid)
return base.Save();
else
return this;
}

This error is due to automated data population from another system. My code allows the user to bring up lists and correct the inputs when necessary.

The message looks like a DialogResult is provided somewhere. I think if they choose to ignore it, the managers may decide to have me automatically delete it, but that's not the best solution always for a case like this. So where can this exception be intercepted in the UI to provide more feedback? A method on the binding source?

If I can get the DialogResult, I could ask them if they'll correct it at a later time, log it or create a to-do list for them to follow up on.

Suggestions?

Thanks in advance,

_E

esteban404 replied on Wednesday, February 11, 2009

I've read all the post that seem to be related, but the UI is still messed up. I've implemented a change:
public override Qcpc Save()
{
if (this.IsValid)
return base.Save();
else
{
return this;
}
}

This effectively returns the object and does not update it. If the user then corrects the displayed error, and moves off the row, it updates fine, otherwise the original value is still present in the database. It will be missing from the grid implying it has been updated.

I tried overriding the SaveItem method in the list also, but the above in the BB class worked better to prevent UEs bubbling to UI. I also tried to return the same object from the database and plumb it in, but it really didn't like that. (Obj not set to instance of obj no matter how I tried to trick it.) The databinding position change calls ApplyEdit() on the object, so cloning it and calling CancelEdit() doesn't do anything, the bad edit is still present.

Is there a way to catch this in the UI when the databinding is updating or changing position? It's OK to refuse to update the item, but the grid needs to show the previous value. If it weren't for this, it'd be done!

_E

Copyright (c) Marimer LLC