using System.Data.Common; using EntitlementDAL.DTOs; using EntitlementDAL.Interfaces; using EntitlementDAL.QueryBuilders; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; namespace EntitlementDAL.Implementations; public class ClientUserRoleDAL : IClientUserRoleDAL { private readonly IQueryExecutor _QueryExecutor; public ClientUserRoleDAL(IQueryExecutor queryExecutor) => _QueryExecutor = queryExecutor; public async Task> GetByClientUserAsync(int clientUserId, LoginDTO login, CancellationToken ct) => await _QueryExecutor.QueryAsync( login, ClientUserRoleQB.GET_BY_CLIENT_USER, new { ClientUserId = clientUserId }, cancellationToken: ct).ConfigureAwait(false) ?? Enumerable.Empty(); public async Task> GetActiveRoleCodesAsync(int clientUserId, LoginDTO login, CancellationToken ct) => await _QueryExecutor.QueryAsync( login, ClientUserRoleQB.GET_ACTIVE_ROLE_CODES, new { ClientUserId = clientUserId }, cancellationToken: ct).ConfigureAwait(false) ?? Enumerable.Empty(); public async Task GrantAsync(ClientUserRoleDTO dto, LoginDTO login, DbTransaction tx, CancellationToken ct) => await _QueryExecutor.ExecuteAsync(login, ClientUserRoleQB.INSERT, dto, tx, cancellationToken: ct).ConfigureAwait(false); public async Task RevokeAsync(int clientUserId, string roleCode, LoginDTO login, DbTransaction tx, CancellationToken ct) => await _QueryExecutor.ExecuteAsync(login, ClientUserRoleQB.REVOKE, new { ClientUserId = clientUserId, RoleCode = roleCode, ModifiedById = login.UserId, ModifiedOn = DateTime.UtcNow }, tx, cancellationToken: ct).ConfigureAwait(false); }