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.NDPHypothesis; using MarketingDAL.Query.NDPHypothesis; using Newtonsoft.Json; namespace MarketingDAL.CustomCode.NDPHypothesis; public class NDPHypothesisDAL : INDPHypothesisDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public NDPHypothesisDAL(IQueryExecutor queryExecutor, IValidation validation) { _QueryExecutor = queryExecutor; _Validation = validation; } public async Task GetNDPHypothesis(int ndpHypothesisId, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _QueryExecutor .QuerySingleAsync(loginDTO, NDPHypothesisQB.GET_NDPHYPOTHESIS, new { NDPHypothesisId = ndpHypothesisId }, cancellationToken: ct) .ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch { throw; } } public async Task GetSelectListNDPHypothesis(CriteriaDTO criteriaDTO, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _QueryExecutor .QueryAsync(loginDTO, NDPHypothesisQB.GET_SELECTLIST_NDPHYPOTHESIS, null!, cancellationToken: ct) .ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch { throw; } } public async Task SaveNDPHypothesis(NDPHypothesisDTO ndpHypothesisDTO, LoginDTO loginDTO, DbTransaction tx, CancellationToken ct) { try { return await _QueryExecutor.ExecuteAsync(loginDTO, NDPHypothesisQB.SAVE_NDPHYPOTHESIS, ndpHypothesisDTO, tx, ct).ConfigureAwait(false); } catch (Exception ex) { string error = await _Validation.HandleException(ex, ErrorResponse.SaveErrorMessage); throw new Exception(error); } } public async Task UpdateNDPHypothesis(NDPHypothesisDTO ndpHypothesisDTO, LoginDTO loginDTO, DbTransaction tx, CancellationToken ct) { try { return await _QueryExecutor.ExecuteAsync(loginDTO, NDPHypothesisQB.UPDATE_NDPHYPOTHESIS, ndpHypothesisDTO, tx, ct).ConfigureAwait(false); } catch (Exception ex) { string error = await _Validation.HandleException(ex, ErrorResponse.UpdateErrorMessage); throw new Exception(error); } } public async Task DeleteNDPHypothesis(int ndpHypothesisId, LoginDTO loginDTO, CancellationToken ct) { try { int result = await _QueryExecutor .ExecuteAsync(loginDTO, NDPHypothesisQB.DELETE_NDPHYPOTHESIS, new { NDPHypothesisId = ndpHypothesisId }, 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); } } }