Using identifier asp.net version of RTW .
I need to perform several actions in a transaction, including function calls UserManangerand other operations on mine DbContext(example: create a new user, add him to a group and perform some business logical operations).
How can I do it?
My thoughts follow.
Transactionaction
using (var scope = new TransactionScope(TransactionScopeOption.Required))
{
if (everythingIsOk) scope.Complete();
}
The problem is that the functions are UserManagerall asynchronous, and TransactionScopenot designed to work with async / await. It seems to be solved in .Net Framework 4.5.1 . But I use Azure Web Sites to host my projects, so I can’t configure it yet 4.5.1.
Database operation
public class SomeController : Controller
{
private MyDbContext DbContext { get; set; }
private UserManager<User> UserManager { get; set; }
public AccountController()
{
DbContext = new MyDbContext()
var userStore = new UserStore<IdentityUser>(DbContext);
UserManager = new UserManager<IdentityUser>(userStore);
}
public async ActionResult SomeAction()
{
using (var tran = DbContext.Database.BeginTransaction())
{
try
{
if (everythingIsOk)
tran.Commit();
else
{
tran.Rollback();
}
}
catch (Exception)
{
tran.Rollback();
}
}
}
}
, ?
UserManager<> IUserStore<>, .
UserStore<> DbContext, , .