using System.Data.Common; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.Validation; using MarketingDAL.DTO.EmotionalDriver; using MarketingDAL.Query.EmotionalDriver; using Newtonsoft.Json; namespace MarketingDAL.CustomCode.EmotionalDriver; public class EmotionalDriverDAL : IEmotionalDriverDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public EmotionalDriverDAL(IQueryExecutor queryExecutor, IValidation validation) { _QueryExecutor = queryExecutor; _Validation = validation; } public async Task GetEmotionalDriver(int emotionalDriverId, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _QueryExecutor .QuerySingleAsync(loginDTO, EmotionalDriverQB.GET_EMOTIONALDRIVER, new { EmotionalDriverId = emotionalDriverId }, cancellationToken: ct) .ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch { throw; } } public async Task GetSelectListEmotionalDriver(CriteriaDTO criteriaDTO, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _QueryExecutor .QueryAsync(loginDTO, EmotionalDriverQB.GET_SELECTLIST_EMOTIONALDRIVER, null!, cancellationToken: ct) .ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch { throw; } } public async Task SaveEmotionalDriver(EmotionalDriverDTO emotionalDriverDTO, LoginDTO loginDTO, DbTransaction tx, CancellationToken ct) { try { return await _QueryExecutor.ExecuteAsync(loginDTO, EmotionalDriverQB.SAVE_EMOTIONALDRIVER, emotionalDriverDTO, tx, ct).ConfigureAwait(false); } catch (Exception ex) { string error = await _Validation.HandleException(ex, ErrorResponse.SaveErrorMessage); throw new Exception(error); } } public async Task UpdateEmotionalDriver(EmotionalDriverDTO emotionalDriverDTO, LoginDTO loginDTO, DbTransaction tx, CancellationToken ct) { try { return await _QueryExecutor.ExecuteAsync(loginDTO, EmotionalDriverQB.UPDATE_EMOTIONALDRIVER, emotionalDriverDTO, tx, ct).ConfigureAwait(false); } catch (Exception ex) { string error = await _Validation.HandleException(ex, ErrorResponse.UpdateErrorMessage); throw new Exception(error); } } public async Task DeleteEmotionalDriver(int emotionalDriverId, LoginDTO loginDTO, CancellationToken ct) { try { int result = await _QueryExecutor .ExecuteAsync(loginDTO, EmotionalDriverQB.DELETE_EMOTIONALDRIVER, new { EmotionalDriverId = emotionalDriverId }, cancellationToken: ct) .ConfigureAwait(false); return result > 0 ? SuccessResponse.DeleteSuccessMessage : ErrorResponse.DeleteNotFoundMessage; } catch (Exception ex) { string error = await _Validation.HandleException(ex, ErrorResponse.DeleteErrorMessage); throw new Exception(error); } } }