using FLSDAL.DTO.Survey; using FLSDAL.Query.Survey; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; namespace FLSDAL.CustomCode.Survey; public class SurveyAnswerDAL : ISurveyAnswerDAL { private readonly IQueryExecutor _qe; public SurveyAnswerDAL(IQueryExecutor queryExecutor) => _qe = queryExecutor; public async Task UpsertAnswersAsync( int flsSessionId, List answers, List answerIds, bool isDraft, LoginDTO login, CancellationToken ct) { for (int i = 0; i < answers.Count; i++) { var a = answers[i]; await _qe.ExecuteAsync( login, SurveyQB.UPSERT_ANSWER, new { SurveyAnswerId = answerIds[i], FlsSessionId = flsSessionId, a.InstQuestionId, AnswerText = a.ResponseText, AnswerNumeric = a.ResponseValue, AnswerOptionIds = a.SelectedOptionIds, IsDraft = isDraft ? 1 : 0, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); } } public async Task> GetBySessionAsync( int flsSessionId, LoginDTO login, CancellationToken ct) => await _qe.QueryAsync( login, SurveyQB.GET_ANSWERS_BY_SESSION, new { FlsSessionId = flsSessionId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false) ?? Enumerable.Empty(); public async Task> GetByRespondentAsync( int flsRespondentId, LoginDTO login, CancellationToken ct) => await _qe.QueryAsync( login, SurveyQB.GET_ANSWERS_BY_RESPONDENT, new { FlsRespondentId = flsRespondentId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false) ?? Enumerable.Empty(); }