Minor fixes for CreateUser

This commit is contained in:
2025-03-16 23:26:15 +01:00
parent 18e713153b
commit f6cd629fe2
4 changed files with 53 additions and 11 deletions

View File

@@ -13,7 +13,7 @@ public interface IUserService
Task<User?> GetUserByGuidAsync(string guid);
Task<User?> GetUserByUsernameAndPassword(string email, string password);
Task<bool> CheckIfEmailIsValid(string email, string? guid = "");
Task<User?> CreateUser(CreateUserRequestData data, Role role);
Task<User?> CreateUserAsync(CreateUserRequestData data, Role role);
}
public class UserService : BaseService, IUserService
@@ -102,16 +102,19 @@ public class UserService : BaseService, IUserService
return valid;
}
public async Task<User?> CreateUser(CreateUserRequestData data, Role role)
public async Task<User?> CreateUserAsync(CreateUserRequestData data, Role role)
{
User? user = null;
using (var transaction = _sqlServerContext.Database.BeginTransactionAsync())
{
var tempUser = this.CreateUserData(data, role);
await _sqlServerContext.Users.AddAsync(tempUser);
await _sqlServerContext.SaveChangesAsync();
await (await transaction).CommitAsync();
user = tempUser;
}
return user;
}