Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

Using events with existing classes in DB

 Post Reply Post Reply
Author
Dino Gomezel View Drop Down
Senior Member
Senior Member
Avatar

Joined: 27 Aug 2018
Posts: 117
Post Options Post Options   Quote Dino Gomezel Quote  Post ReplyReply Direct Link To This Post Topic: Using events with existing classes in DB
    Posted: 27 Mar 2020 at 6:33pm
Hi!

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)

TDocument: class
  Id: integer
  Items: Proxy<TDocItem>
end;

TDocItem: class
  Id: integer;
  StockItem: TStockItem;
  Qty: integer;
end;

TStockItem: class
  Id: integer;
  OnStock: integer;
end;

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 :)
Back to Top
Dino Gomezel View Drop Down
Senior Member
Senior Member
Avatar

Joined: 27 Aug 2018
Posts: 117
Post Options Post Options   Quote Dino Gomezel Quote  Post ReplyReply Direct Link To This Post Posted: 27 Mar 2020 at 6:35pm
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.
Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2889
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post Posted: 27 Mar 2020 at 10:00pm
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.

Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2889
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post Posted: 27 Mar 2020 at 10:01pm
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?
Back to Top
Dino Gomezel View Drop Down
Senior Member
Senior Member
Avatar

Joined: 27 Aug 2018
Posts: 117
Post Options Post Options   Quote Dino Gomezel Quote  Post ReplyReply Direct Link To This Post Posted: 01 Apr 2020 at 1:05pm
Hi!

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).
Back to Top
Wagner R. Landgraf View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 2889
Post Options Post Options   Quote Wagner R. Landgraf Quote  Post ReplyReply Direct Link To This Post Posted: 02 Apr 2020 at 2:19pm
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.
Back to Top
Dino Gomezel View Drop Down
Senior Member
Senior Member
Avatar

Joined: 27 Aug 2018
Posts: 117
Post Options Post Options   Quote Dino Gomezel Quote  Post ReplyReply Direct Link To This Post Posted: 03 Apr 2020 at 11:29am
This is it! Thank you!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down