Open chinasqzl opened 4 years ago
I think you can use content events for that
@hishamco Don't understand, when the event is triggered, the deletion is complete. Is there an example in the source code?
There are many event for the content such as: created, loaded, removed .. etc, have a look to https://github.com/OrchardCMS/OrchardCore/blob/dev/src/OrchardCore/OrchardCore.ContentManagement/Handlers/ContentsHandler.cs
@hishamco Blocking deletions is determined by the parts business, and using content events is not good.
I didn't under stand you, and how telling that using content events is not good?!!
InStockPicking (contentType) -TitlePart -StockPickingPart
Stock picking part, after publication, can not be deleted, can not be modified. Non-removable properties are determined by the part, so should be written in the part's StockPickingPartHandler.RemovingAsync.
In content events, i want to determine whether StockPickingPart is included?
the content admin controller needs to check if the ModelState is valid before invoking RemoveAsync(), and call session.Cancel()
if not.
I think it's up to the called or RemoveAsync (or UpdateAsync) to check for ModelState errors and cancel the transaction or display error messages.
As a mitigation, you can call _session.Cancel()
until we fix the issue. That will prevent the database from being committed. Yo ucan also use INotifier
to render an error message.
@sebastienros I used the _session.Cancel()
as a work around and found 2 issues:
_session.Cancel()
doesn't work for Media field. The record deletion in the data is cancelled, however the media associate with it is deleted.
Is there any workaround for this ?.
Or is there any way to call my custom API for the deletion?. We have some helpers that we already use in some places, allowing to execute things through delegates, but only if the session was not canceled, and moreover only if the session was committed sucessfully. They are useful when doing things not directly related to the ambient session, but still correlated to a content item being updated, as in your case ;)
We already added recently this pattern in some places, but yes there are some remaining places that still need to be adapted, e.g. here i think some media handlers, I will take a look on this issue more in details this night