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.GrowthPlay; using MarketingDAL.Query.GrowthPlay; using Newtonsoft.Json; namespace MarketingDAL.CustomCode.GrowthPlay; public class GrowthPlayDAL : IGrowthPlayDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public GrowthPlayDAL(IQueryExecutor queryExecutor, IValidation validation) { _QueryExecutor = queryExecutor; _Validation = validation; } public async Task GetGrowthPlay(int growthPlayId, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _QueryExecutor .QuerySingleAsync(loginDTO, GrowthPlayQB.GET_GROWTHPLAY, new { GrowthPlayId = growthPlayId }, cancellationToken: ct) .ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch { throw; } } public async Task GetSelectListGrowthPlay(CriteriaDTO criteriaDTO, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _QueryExecutor .QueryAsync(loginDTO, GrowthPlayQB.GET_SELECTLIST_GROWTHPLAY, null!, cancellationToken: ct) .ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch { throw; } } public async Task SaveGrowthPlay(GrowthPlayDTO growthPlayDTO, LoginDTO loginDTO, DbTransaction tx, CancellationToken ct) { try { return await _QueryExecutor .ExecuteAsync(loginDTO, GrowthPlayQB.SAVE_GROWTHPLAY, growthPlayDTO, tx, ct) .ConfigureAwait(false); } catch (Exception ex) { string error = await _Validation.HandleException(ex, ErrorResponse.SaveErrorMessage); throw new Exception(error); } } public async Task UpdateGrowthPlay(GrowthPlayDTO growthPlayDTO, LoginDTO loginDTO, DbTransaction tx, CancellationToken ct) { try { return await _QueryExecutor .ExecuteAsync(loginDTO, GrowthPlayQB.UPDATE_GROWTHPLAY, growthPlayDTO, tx, ct) .ConfigureAwait(false); } catch (Exception ex) { string error = await _Validation.HandleException(ex, ErrorResponse.UpdateErrorMessage); throw new Exception(error); } } public async Task DeleteGrowthPlay(int growthPlayId, LoginDTO loginDTO, CancellationToken ct) { try { int result = await _QueryExecutor .ExecuteAsync(loginDTO, GrowthPlayQB.DELETE_GROWTHPLAY, new { GrowthPlayId = growthPlayId }, 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); } } }