I have a question about Aurelius and XData. I posted here, because the problem/solution is in Aurelus, bu if I'm wrong, I'll post on the XData part of the forum.
I 'm creating an app that rread/write through XData. The classes that I use are (very simplified, just properties)
When saving, I update the TStockItem.OnStock with TDocItem.Qty when saving the TDocument. I can do this using the event OnUpdated and going through all TDocument.Items to update the stocks.
My problem is that when I edit an existing document, I would like to update the stock before updating the TDocument. So I would need the old document (the one that is still in the DB) and change the stocks based on the old document items.
Basically I would like to do this:
12:00:00 Product1: stock=10
12:01:00 Editing the doucment, changing Product1 Qty from 5 to 6
12:02:00 Staring to save the document
12:02:01 (OnUpdating) Change to Product1 = 10 + 5 --> 15
12:02:02 (OnUpdated) Change to Product1 = 15 - 6 --> 9
Hope I explained the problem good enough :)
I forgor why to use Aurelius events: Only using events I can assure that the business logic will be on server-side.
I can do it also via XData serivices, but I would like that the client app sees just XData classes, no additional methods and avoid that TDcoument can be saved directly and not via service method.
You contradicted yourself. You want to avoid TDocumento to be saved directly? In this case you should use a service operation.
In any case, both OnUpdating and OnUpdated events have old and current value of Qty column. Isn't that enough for you to update the stock?
First, thank you for the answer. My problem is that an user can load a document, remove a row from Doc.Items and save it. In this case my amm need to "feel" that there is a row less and update the stock according to this (in this example, add qty to the stock, because the row is not anymore in the document).
There are also events OnCollectionItemAdded and OnCollectionItemRemoved for those cases.
Also note that nothing prevents you from using service operations for that, or database triggers.