I got database is lock when run below code, could you tell me how to resolve it.
I want to create an new user. I refer my user table with UserAuth. So i must add user first and get it’s id, but i also want to add them in a transaction.
public object Post(CreateUser request)
{
UserResponse userResponse;
using (var dbTrans = Db.OpenTransaction())
{
var user = new User();
user.ClassId = request.ClassId;
user.KindergartenId = request.KindergartenId;
user.RoleType = request.RoleType;
user.RealName = request.DisplayName;
user.LoginName = request.UserName;
Db.Save(user);
var authRepo = this.TryResolve<IUserAuthRepository>();
var newUserAuth = new UserAuth();
newUserAuth.DisplayName = request.DisplayName;
newUserAuth.UserName = request.UserName;
newUserAuth.PhoneNumber = request.PhoneNumber;
newUserAuth.RefId = user.Id;
//Create New GetUsers Account with oldUser Password
var iUserAuth = authRepo.CreateUserAuth(newUserAuth, request.Password);
newUserAuth.Id = iUserAuth.Id;
if (request.RoleType == 1)
{
authRepo.AssignRoles(iUserAuth, new List<string>() { "Parent" });
}
else if (request.RoleType == 2)
{
authRepo.AssignRoles(iUserAuth, new List<string>() { "Teacher" });
}
else if (request.RoleType == 3)
{
authRepo.AssignRoles(iUserAuth, new List<string>() { "Master" });
}
{
var ret = Db.Single<UV_UserAuthAndUser>(u => u.Id == iUserAuth.Id);
userResponse = new UserResponse().PopulateWith(ret);
}
dbTrans.Commit();
}
return userResponse;
}