using AutomationDAL.DTO.Target; using AutomationDAL.Query.Target; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; namespace AutomationDAL.CustomCode.Target; public class TargetDAL : ITargetDAL { private readonly IQueryExecutor _qe; public TargetDAL(IQueryExecutor qe) => _qe = qe; public async Task GetById(int targetId, LoginDTO login, CancellationToken ct) { var rows = await _qe.QueryAsync(login, TargetQB.GET_BY_ID, new { TargetId = targetId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); return rows.FirstOrDefault(); } public async Task> GetByScript(int scriptId, LoginDTO login, CancellationToken ct) => await _qe.QueryAsync(login, TargetQB.GET_BY_SCRIPT, new { ScriptId = scriptId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); public async Task Insert(TargetDTO dto, LoginDTO login, CancellationToken ct) => await _qe.ExecuteIdentityAsync(login, TargetQB.INSERT, new { dto.ScriptId, dto.TargetName, dto.Environment, dto.TargetUrl, dto.CredentialVaultRef, dto.ConcurrencyLimit, dto.CalendarId, TenantId = login.ClientId, CreatedById = login.UserId }).ConfigureAwait(false); public async Task Update(TargetDTO dto, LoginDTO login, CancellationToken ct) => await _qe.ExecuteAsync(login, TargetQB.UPDATE, new { dto.TargetId, dto.TargetName, dto.Environment, dto.TargetUrl, dto.CredentialVaultRef, dto.ConcurrencyLimit, dto.CalendarId, TenantId = login.ClientId, ModifiedById = login.UserId }, cancellationToken: ct).ConfigureAwait(false); public async Task Enable(int targetId, int approvedById, int createdById, LoginDTO login, CancellationToken ct) => await _qe.ExecuteAsync(login, TargetQB.ENABLE, new { TargetId = targetId, ApprovedById = approvedById, CreatedById = createdById, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); public async Task Disable(int targetId, LoginDTO login, CancellationToken ct) => await _qe.ExecuteAsync(login, TargetQB.DISABLE, new { TargetId = targetId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); }