first commit

This commit is contained in:
Dhananjaya99
2026-09-28 11:51:12 +05:30
commit 73056da0d5
57 changed files with 7654 additions and 0 deletions
+53
View File
@@ -0,0 +1,53 @@
using AuthHex.Interfaces;
using AuthHex.Models;
using Microsoft.EntityFrameworkCore;
namespace AuthHex.Repos
{
public class RoleRepository : IRoleRepository
{
private readonly AppDBContext _dbContext;
public RoleRepository(AppDBContext dbContext)
{
_dbContext = dbContext;
}
public Task<Role> AddRoleAsync(Role role, CancellationToken ct = default)
{
// SaveChanges is deferred to the Unit of Work commit, mirroring UserManageRepository.
_dbContext.Roles.Add(role);
return Task.FromResult(role);
}
public async Task<Role?> GetByIdAsync(Guid roleId, CancellationToken ct = default)
{
return await _dbContext.Roles.FirstOrDefaultAsync(r => r.RoleId == roleId, ct);
}
public async Task<Role?> GetByCodeAsync(string code, CancellationToken ct = default)
{
return await _dbContext.Roles.FirstOrDefaultAsync(r => r.Code == code, ct);
}
public async Task<List<Role>> ListAsync(CancellationToken ct = default)
{
return await _dbContext.Roles
.AsNoTracking()
.OrderBy(r => r.Code)
.ToListAsync(ct);
}
public async Task<bool> IsAssignedToAnyUserAsync(Guid roleId, CancellationToken ct = default)
{
return await _dbContext.Users.AnyAsync(u => u.RoleId == roleId, ct);
}
public Task DeleteRoleAsync(Role role, CancellationToken ct = default)
{
// SaveChanges is deferred to the Unit of Work commit.
_dbContext.Roles.Remove(role);
return Task.CompletedTask;
}
}
}