Problem with deferred deletion

Problem with deferred deletion

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


jrlopher posted on Wednesday, June 07, 2006

Hello all, I've a new problem with the business objects in my project (CSLA 1.0). If I want to use the deferred deletion in a root object and there are some cases in which the delete operation is forbidden, how can I use the broken rules to mantain this logic?. For example, an object is marked for deletion but we are in a case in which the operation shouldn't be allowed. When the Save method is called I would like to have that broken rule in the broken rules collection. But if I've marked an object for deletion, how could I restore the undeleted state?

Thanks in advance.

Jose

ajj3085 replied on Wednesday, June 07, 2006

Hmm,

You'll have to tie your business rule to the collection property of your root.  You'll also need to hook into the collection's ListChanged event.

When ListChanged is called, call ValidationRules.CheckRules( "collProperty").

This will likely have to call a method on your collection to check for items which are deleted by should not be.

Of course the problem is fixing the object; do you provide an undelete?  How do you show the items which are deleted by can be recovered?  I don't think the DeletedList can be seen, so you may need to create a property DeletedItems which allows a readonly view of the collection.

HTH
Andy

ajj3085 replied on Wednesday, June 07, 2006

As an aside, it might make sense for BusinessListBase to offer up a BrokenRules property, just like BusinessBase does.

The purpose of having rules there would be to store rules which don't apply to an individual item, but only when looking at the collection as a whole.  For example, you aren't allowed to add DiscountLineItem more than once (only one discount per order).

I know there was a thread about this on the old forum, but it may be worth bringing the discussion back.

Andy

Mark replied on Wednesday, June 07, 2006

I don't think he was asking about a child collection - more of how to prevent a deferred delete on a root object.  For example, you might have a PurchaseOrder object that is in <some state> that indicates you can't make a deferred Delete call.

Ideally, you'd override the Delete method and throw an exception so it never gets marked as deleted to begin with, but alas, Delete is not marked as overridable in Core.BusinessBase.

The only other option is to override Save() and catch it there.  You have to rely on the client using n-level undo to get back to the prior state via a CancelEdit call.

Rocky - any chance of providing an overridable deferred 'Delete' method in CSLA, or do you see a better way of handling this?

ajj3085 replied on Wednesday, June 07, 2006

Ah, a root object defered delete.. it was still early.

This is a good question, I'm not sure a good way to do this within the framework.

Andy

RockfordLhotka replied on Wednesday, June 07, 2006

No, it certainly appears that Delete() should be virtual/Overridable. This change will be in 2.0.2 then.

jrlopher replied on Thursday, June 08, 2006

Thanks for your responses.

Copyright (c) Marimer LLC