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 EntitlementGrantDAL : IEntitlementGrantDAL { private readonly IQueryExecutor _QueryExecutor; public EntitlementGrantDAL(IQueryExecutor queryExecutor) => _QueryExecutor = queryExecutor; public async Task GetByIdAsync(int entitlementId, LoginDTO login, CancellationToken ct) => await _QueryExecutor.QuerySingleAsync( login, EntitlementGrantQB.GET_BY_ID, new { EntitlementId = entitlementId }, cancellationToken: ct).ConfigureAwait(false); public async Task> GetBySubscriptionAsync(int subscriptionId, LoginDTO login, CancellationToken ct) => await _QueryExecutor.QueryAsync( login, EntitlementGrantQB.GET_BY_SUBSCRIPTION, new { SubscriptionId = subscriptionId }, cancellationToken: ct).ConfigureAwait(false) ?? Enumerable.Empty(); public async Task GetBySubscriptionAndFeatureAsync(int subscriptionId, int featureId, LoginDTO login, CancellationToken ct) => await _QueryExecutor.QuerySingleAsync( login, EntitlementGrantQB.GET_BY_SUBSCRIPTION_AND_FEATURE, new { SubscriptionId = subscriptionId, FeatureId = featureId }, cancellationToken: ct).ConfigureAwait(false); public async Task> GetListPagedAsync( int clientId, int featureId, int entitlementSource, int isEnabled, int offset, int pageSize, LoginDTO login, CancellationToken ct) => await _QueryExecutor.QueryPagedAsync( login, EntitlementGrantQB.GET_LIST_PAGED, new { ClientId = clientId, FeatureId = featureId, EntitlementSource = entitlementSource, IsEnabled = isEnabled, Offset = offset, PageSize = pageSize }) .ConfigureAwait(false); public async Task GetByClientAndFeatureCodeAsync(int clientId, string featureCode, LoginDTO login, CancellationToken ct) => await _QueryExecutor.QuerySingleAsync( login, EntitlementGrantQB.GET_BY_CLIENT_AND_FEATURE_CODE, new { ClientId = clientId, FeatureCode = featureCode }, cancellationToken: ct).ConfigureAwait(false); public async Task SaveAsync(EntitlementDTO dto, LoginDTO login, DbTransaction tx, CancellationToken ct) => await _QueryExecutor.ExecuteAsync(login, EntitlementGrantQB.INSERT, dto, tx, cancellationToken: ct).ConfigureAwait(false); public async Task UpdateAsync(EntitlementDTO dto, LoginDTO login, DbTransaction tx, CancellationToken ct) => await _QueryExecutor.ExecuteAsync(login, EntitlementGrantQB.UPDATE, dto, tx, cancellationToken: ct).ConfigureAwait(false); public async Task DeleteAsync(int entitlementId, LoginDTO login, DbTransaction tx, CancellationToken ct) => await _QueryExecutor.ExecuteAsync(login, EntitlementGrantQB.DELETE, new { EntitlementId = entitlementId }, tx, cancellationToken: ct).ConfigureAwait(false); }