using System.Linq; using System.Threading; using System.Threading.Tasks; using FrameworkDAL.Query.Promotion; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; namespace FrameworkDAL.CustomCode.Promotion { public class ReportCodeLookupDAL : IReportCodeLookupDAL { private readonly IQueryExecutor _qe; public ReportCodeLookupDAL(IQueryExecutor qe) => _qe = qe; public async Task GetReportCodeById(int reportId, LoginDTO login, CancellationToken ct) { var rows = await _qe.QueryAsync(login, ReportCodeLookupQB.GET_CODE_BY_ID, new { ReportId = reportId }, cancellationToken: ct).ConfigureAwait(false); return rows.FirstOrDefault(); } public async Task GetReportIdByCode(string reportCode, LoginDTO login, CancellationToken ct) { var rows = await _qe.QueryAsync(login, ReportCodeLookupQB.GET_ID_BY_CODE, new { ReportCode = reportCode }, cancellationToken: ct).ConfigureAwait(false); var list = rows.ToList(); return list.Count > 0 ? list[0] : (int?)null; } } }