Instance related rules for deleting objects

Instance related rules for deleting objects

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


detritus posted on Tuesday, September 16, 2008

Hi All,

I've seen some topics about this usually around the requirement to check if the BO is used in another BO before deleting it and recommendation usually is to solve it with Command object to help the UI, etc.

Our design dictates some system defined records in addition to user-definable ones. We don't want "any" user to delete system defined BOs. Other that some key value (like Id < 0) there is no difference between system defined and user defined BO.

Where to check if the user is trying to delete a system defined BO? The only place I can think of is inside DataPortal_Delete but I'm not sure if this is correct.

TIA

IanK replied on Thursday, September 25, 2008

Why not add a property to your object such as

Public  ReadOnly Property IsDeletable() as boolean

   Get

      CanReadProperty(True)

      Return (Me.Id  < 0)

End Get

END PROPERTY

You could then bind the property to your enabled property of the delete button or simply check value prior to executing delete. This would avoid throwing exceptions and avoid a strip to next tier.

 

detritus replied on Friday, September 26, 2008

> simply check value prior to executing delete
That's what I'm actually asking. Is this check should be done inside DataPortal_Delete? Should we do these kind of things inside methods talking with DAL or is there a better place to put these kinds of checks?

Thanks

JoeFallon1 replied on Friday, September 26, 2008

You should do it before getting to the DataPortal call.

1. So in your UI, if a user wants to click a Delete button it won't be enabled if it is bound to your BO in the new proeprty described earlier.

2. If for some reason the user manages to click the button anyway, then your BO code that calls DataPortal Delete can have a check in it prior to making the call. If the check fails, then don't make the call and return a message to the UI.

Joe

 

 

detritus replied on Friday, September 26, 2008

Thanks Joe,

That will do the trick. It's strange though, with all the bells and whistles integrated in to the framework I expect this kind of thing already have its place. Spent a lot of time looking for a method to override :)

Sinan

Copyright (c) Marimer LLC