using System.Threading; using System.Threading.Tasks; using FrameworkDAL.DTO.Promotion; using FrameworkDAL.Query.Promotion; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; namespace FrameworkDAL.CustomCode.Promotion { public class PromotionAssetLinkDAL : IPromotionAssetLinkDAL { private readonly IQueryExecutor _qe; public PromotionAssetLinkDAL(IQueryExecutor qe) => _qe = qe; public async Task GetByOrigin( string originEnvironmentCode, string entityTypeCode, int originEntityId, LoginDTO login, CancellationToken ct) { var rows = await _qe.QueryAsync(login, PromotionAssetLinkQB.GET_BY_ORIGIN, new { OriginEnvironmentCode = originEnvironmentCode, EntityTypeCode = entityTypeCode, OriginEntityId = originEntityId }, cancellationToken: ct).ConfigureAwait(false); foreach (var row in rows) return row; // at most one row — UX_MPROMOTIONASSETLINK_ORIGIN enforces this return null; } public async Task Insert(PromotionAssetLinkDTO dto, LoginDTO login, CancellationToken ct) => await _qe.ExecuteIdentityAsync(login, PromotionAssetLinkQB.INSERT, new { dto.OriginEnvironmentCode, dto.EntityTypeCode, dto.OriginEntityId, dto.DestinationEntityId, dto.LastGopExecutionId, dto.LastPromotedOn, UserId = login.UserId }); public async Task UpdateAfterPromotion(PromotionAssetLinkDTO dto, LoginDTO login, CancellationToken ct) => await _qe.ExecuteAsync(login, PromotionAssetLinkQB.UPDATE_AFTER_PROMOTION, new { dto.PromotionAssetLinkId, dto.DestinationEntityId, dto.LastGopExecutionId, dto.LastPromotedOn, UserId = login.UserId }, cancellationToken: ct).ConfigureAwait(false); } }