Fixing coverage

This commit is contained in:
2025-03-23 19:50:32 +01:00
parent 61f7504e66
commit e5a3e6fdcf
4 changed files with 12 additions and 78 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?> CreateUserAsync(CreateUserRequestData data, Role role);
Task<User> CreateUserAsync(CreateUserRequestData data, Role role);
Task<bool?> DeleteUserAsync(User user);
}
@@ -102,17 +102,15 @@ public class UserService : BaseService, IUserService
return valid;
}
public async Task<User?> CreateUserAsync(CreateUserRequestData data, Role role)
public async Task<User> CreateUserAsync(CreateUserRequestData data, Role role)
{
User? user = null;
User user = this.CreateUserData(data, role);
using (var transaction = _sqlServerContext.Database.BeginTransactionAsync())
{
var tempUser = this.CreateUserData(data, role);
await _sqlServerContext.Users.AddAsync(tempUser);
await _sqlServerContext.Users.AddAsync(user);
await _sqlServerContext.SaveChangesAsync();
await (await transaction).CommitAsync();
user = tempUser;
}
return user;