using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using WiDAL.Query.Wi; namespace WiDAL.CustomCode.WiStepContentChecklistResponse; public class WiStepContentChecklistResponseDAL : IWiStepContentChecklistResponseDAL { private readonly IQueryExecutor _qe; public WiStepContentChecklistResponseDAL(IQueryExecutor qe) => _qe = qe; public async Task GetResponse(int wiStepContentId, int employeeId, LoginDTO login, CancellationToken ct) { // No prior response is the common case (first view) — QueryAsync + FirstOrDefault, not // QuerySingleAsync, which throws on an empty result set. var rows = await _qe.QueryAsync(login, WiStepContentChecklistResponseQB.GET_RESPONSE, new { WiStepContentId = wiStepContentId, EmployeeId = employeeId, TenantId = login.ClientId }, cancellationToken: ct); return rows.FirstOrDefault(); } public async Task SaveResponse(int wiStepContentId, int employeeId, string responseJson, LoginDTO login, CancellationToken ct) { return await _qe.ExecuteAsync(login, WiStepContentChecklistResponseQB.UPSERT_RESPONSE, new { WiStepContentId = wiStepContentId, EmployeeId = employeeId, ResponseJson = responseJson, ModifiedById = login.UserId, TenantId = login.ClientId }, cancellationToken: ct); } }