using AuthHex.Interfaces; using AuthHex.Models; using Microsoft.EntityFrameworkCore; namespace AuthHex.Repos { public class RoleManageRepository : IRoleManageRepository { private readonly AppDBContext _dbContext; public RoleManageRepository(AppDBContext dbContext) { _dbContext = dbContext; } public Task AddRoleAsync(Role role, CancellationToken ct = default) { _dbContext.Roles.Add(role); return Task.FromResult(role); } public async Task GetRoleByIdAsync(Guid roleId, CancellationToken ct = default) { return await _dbContext.Roles.FirstOrDefaultAsync(r => r.RoleId == roleId, ct); } public async Task> ListRolesAsync(CancellationToken ct = default) { return await _dbContext.Roles.OrderBy(r => r.Code).ToListAsync(ct); } public async Task RoleInUseAsync(Guid roleId, CancellationToken ct = default) { return await _dbContext.Users.AnyAsync(u => u.RoleId == roleId, ct); } public Task DeleteRoleAsync(Role role, CancellationToken ct = default) { _dbContext.Roles.Remove(role); return Task.CompletedTask; } } }