using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using GB5Shared.QueryExecutor; using PromotionExchangeDAL.Common; using PromotionExchangeDAL.DTO; using PromotionExchangeDAL.Query; namespace PromotionExchangeDAL.CustomCode; public class ExchangePackageDAL : IExchangePackageDAL { private readonly IQueryExecutor _qe; private readonly IPromotionExchangeSystemContext _systemContext; public ExchangePackageDAL(IQueryExecutor qe, IPromotionExchangeSystemContext systemContext) { _qe = qe; _systemContext = systemContext; } public async Task Insert(ExchangePackageDTO dto, CancellationToken ct) { var login = _systemContext.GetSystemLogin(); return await _qe.ExecuteIdentityAsync(login, ExchangePackageQB.INSERT, new { dto.OriginEnvironmentCode, dto.DestinationEnvironmentCode, dto.PackageBytes, dto.PackageSizeBytes }).ConfigureAwait(false); } public async Task> GetPendingForDestination( string destinationEnvironmentCode, CancellationToken ct) { var login = _systemContext.GetSystemLogin(); return await _qe.QueryAsync(login, ExchangePackageQB.GET_PENDING_FOR_DESTINATION, new { DestinationEnvironmentCode = destinationEnvironmentCode }, cancellationToken: ct).ConfigureAwait(false); } public async Task GetByIdForDestination( int packageId, string destinationEnvironmentCode, CancellationToken ct) { var login = _systemContext.GetSystemLogin(); var rows = await _qe.QueryAsync(login, ExchangePackageQB.GET_BY_ID_FOR_DESTINATION, new { PackageId = packageId, DestinationEnvironmentCode = destinationEnvironmentCode }, cancellationToken: ct).ConfigureAwait(false); var list = new List(rows); return list.Count > 0 ? list[0] : null; } public async Task MarkDownloaded(int packageId, CancellationToken ct) { var login = _systemContext.GetSystemLogin(); await _qe.ExecuteAsync(login, ExchangePackageQB.MARK_DOWNLOADED, new { PackageId = packageId }, cancellationToken: ct).ConfigureAwait(false); } }