Changed CreateUserAsync to avoid silent transaction failure - 2
This commit is contained in:
@@ -20,6 +20,7 @@ public interface IUserService
|
|||||||
|
|
||||||
public class UserService : BaseService, IUserService
|
public class UserService : BaseService, IUserService
|
||||||
{
|
{
|
||||||
|
private readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
|
||||||
public UserService(
|
public UserService(
|
||||||
IHttpContextAccessor httpContextAccessor,
|
IHttpContextAccessor httpContextAccessor,
|
||||||
IConfiguration configuration,
|
IConfiguration configuration,
|
||||||
@@ -111,7 +112,9 @@ public class UserService : BaseService, IUserService
|
|||||||
{
|
{
|
||||||
User? user = null;
|
User? user = null;
|
||||||
|
|
||||||
using (var transaction = await _sqlServerContext.Database.BeginTransactionAsync())
|
using var transaction = await _sqlServerContext.Database.BeginTransactionAsync();
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var tempUser = CreateUserData(data, role);
|
var tempUser = CreateUserData(data, role);
|
||||||
await _sqlServerContext.Users.AddAsync(tempUser);
|
await _sqlServerContext.Users.AddAsync(tempUser);
|
||||||
@@ -119,6 +122,11 @@ public class UserService : BaseService, IUserService
|
|||||||
await transaction.CommitAsync();
|
await transaction.CommitAsync();
|
||||||
user = tempUser;
|
user = tempUser;
|
||||||
}
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
Logger.Error(exception, $"[UserService][CreateUserAsync]");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user