Added role update endpoint

This commit is contained in:
2025-03-28 20:19:26 +01:00
parent f64e367645
commit d52c385e7c
3 changed files with 371 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ public interface IRoleService
Task<Role?> GetRoleByGuidAsync(string guid);
Task<bool> CheckIfNameIsValid(string name, string? guid = "");
Task<Role?> CreateRoleAsync(CreateRoleRequestData data);
Task<Role?> UpdateRoleAsync(CreateRoleRequestData data, Role role);
Task<Role?> GetRoleForUser(string? guid);
Task<bool?> DeleteRoleAsync(Role role);
}
@@ -113,6 +114,30 @@ public class RoleService : BaseService, IRoleService
return role;
}
public async Task<Role?> UpdateRoleAsync(CreateRoleRequestData data, Role role)
{
using var transaction = await _sqlServerContext.Database.BeginTransactionAsync();
try
{
role.Name = data.Name;
role.IsNotEditable = data.IsNotEditable;
role.UpdateTime = DateTime.UtcNow;
role.UpdateUserId = this.GetCurrentUserId();
_sqlServerContext.Roles.Update(role);
await _sqlServerContext.SaveChangesAsync();
await transaction.CommitAsync();
}
catch (Exception exception)
{
await transaction.RollbackAsync();
Logger.Error(exception, $"[RoleService][UpdateRoleAsync]");
}
return role;
}
public async Task<Role?> GetRoleForUser(string? guid)
{
Role? role = null;