using System.Linq; using System.Threading; using System.Threading.Tasks; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using WiDAL.Query.Promotion; namespace WiDAL.CustomCode.Promotion { public class WiProcessCodeLookupDAL : IWiProcessCodeLookupDAL { private readonly IQueryExecutor _qe; public WiProcessCodeLookupDAL(IQueryExecutor qe) => _qe = qe; public async Task GetWiProcessCodeById(int wiProcessId, LoginDTO login, CancellationToken ct) { var rows = await _qe.QueryAsync(login, WiProcessCodeLookupQB.GET_CODE_BY_ID, new { WiProcessId = wiProcessId, TenantId = login.ClientId }, cancellationToken: ct) .ConfigureAwait(false); return rows.FirstOrDefault(); } public async Task GetWiProcessIdByCode(string wiProcessCode, LoginDTO login, CancellationToken ct) { var rows = await _qe.QueryAsync(login, WiProcessCodeLookupQB.GET_ID_BY_CODE, new { WiProcessCode = wiProcessCode, TenantId = login.ClientId }, cancellationToken: ct) .ConfigureAwait(false); var list = rows.ToList(); return list.Count > 0 ? list[0] : (int?)null; } } }