Is it possible to change Delete behavior?

Is it possible to handle 'Delete' using XDataServer EntityDeleting event and, stop subsequent actions, and still have a regular/correct reponse?

Cenario: I need to have "soft deletes" for some Entities (instead of deleting from database, I have to update a 'deleted' field to true).

The API must still use the DELETE http method. In current XData version I can "override" the delete action using a service but, this way I would have to write many services. So, I'm wondering if I can change the deleting behavior using EntityDeleting:

procedure MyXDataModule.XDataServerEntityDeleting(Sender: TObject; Args: TEntityDeletingArgs);
var
  E: TMyEntity;
  M: TObjectManager;
begin
  if Args.Entity is TMyEntity then
  begin
    E := Args.Entity as TMyEntity;
    M := GetSomeObjectManager;
    DoMyFakeDeleteAction(E, M);
    { how to stop here from actually deleting. And have a correct response }
  end;
end;

Regards,

Unfortunately that is not currently possible. The only way to stop the execution flow is to raise an exception.

Ok. Thanks @wlandgraf

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.