Editor PostCreate with Transactions

Editor PostCreate with Transactions

blcarter14@gmail.comblcarter14@gmail.com Posts: 2Questions: 1Answers: 0

I have created a .NET PostCreate event that needs to be fired after a new user is created in my web app. I use the AspNet.Identity UserManager to handle sending out confirmation / change password email after the account is created inside the postCreate event. I am also setting some user roles, so I need to keep Transactions on. The issue is that the PostCreate event is fired before the Transaction is committed to the database. So when the UserManager is called to lookup the user, the user hasn't been saved to the database yet (transaction not committed). Ideally, the postcreate event wouldn't fire until the transaction has been committed. Is there a work around for this?

Answers

  • rf1234rf1234 Posts: 1,073Questions: 48Answers: 145
    edited February 14

    Hi I am not using .NET but PHP but the usual way to end a transaction is the simple command "endTransaction".

    I see that .NET has the same thing:
    https://www.techrepublic.com/article/implementing-sql-server-transactions-with-adonet/

    You need to make sure that the plugin you are using is actually issuing a "beginTransaction" command before you end it, I guess. But I would experiment with this a little to figure it out.

  • blcarter14@gmail.comblcarter14@gmail.com Posts: 2Questions: 1Answers: 0

    Because Editor is handling the transaction I don't have a way to access the transaction to tell it to commit. If I did, then there could be an issue when Editor tries to commit. What I ended up doing is, after the form is processed I have a DtResponse object. If the action was "create" and the DtResponse has return data, with no errors, then I know the transaction has been committed successfully. I then send the Emails from there instead of the PostCreate method. If anyone has a better way of handling this I'm all ears.

  • colincolin Posts: 7,698Questions: 0Answers: 1,298

    PostCreate on the server is called after the row has been commited - the fourth parameter is the row as read from the server so that should also work for you at that point - see server-side events here.

    On the client, you could use submitComplete, which should have the same effect.

    Colin

Sign In or Register to comment.