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.CustomerProductMatrixCell; using MarketingDAL.Query.CustomerProductMatrixCell; using Newtonsoft.Json; namespace MarketingDAL.CustomCode.CustomerProductMatrixCell; public class CustomerProductMatrixCellDAL : ICustomerProductMatrixCellDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public CustomerProductMatrixCellDAL(IQueryExecutor queryExecutor, IValidation validation) { _QueryExecutor = queryExecutor; _Validation = validation; } public async Task GetCustomerProductMatrixCell(int customerProductMatrixCellId, LoginDTO loginDTO, CancellationToken ct) { try { return await _QueryExecutor .QuerySingleAsync(loginDTO, CustomerProductMatrixCellQB.GET_CUSTOMERPRODUCTMATRIXCELL, new { CustomerProductMatrixCellId = customerProductMatrixCellId }, cancellationToken: ct) .ConfigureAwait(false); } catch { throw; } } public async Task GetSelectListCustomerProductMatrixCell(CriteriaDTO criteriaDTO, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _QueryExecutor .QueryAsync(loginDTO, CustomerProductMatrixCellQB.GET_SELECTLIST_CUSTOMERPRODUCTMATRIXCELL, null!, cancellationToken: ct) .ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch { throw; } } public async Task SaveCustomerProductMatrixCell(CustomerProductMatrixCellDTO customerProductMatrixCellDTO, LoginDTO loginDTO, DbTransaction tx, CancellationToken ct) { try { return await _QueryExecutor .ExecuteAsync(loginDTO, CustomerProductMatrixCellQB.SAVE_CUSTOMERPRODUCTMATRIXCELL, customerProductMatrixCellDTO, tx, ct) .ConfigureAwait(false); } catch (Exception ex) { string error = await _Validation.HandleException(ex, ErrorResponse.SaveErrorMessage); throw new Exception(error); } } public async Task UpdateCustomerProductMatrixCell(CustomerProductMatrixCellDTO customerProductMatrixCellDTO, LoginDTO loginDTO, DbTransaction tx, CancellationToken ct) { try { return await _QueryExecutor .ExecuteAsync(loginDTO, CustomerProductMatrixCellQB.UPDATE_CUSTOMERPRODUCTMATRIXCELL, customerProductMatrixCellDTO, tx, ct) .ConfigureAwait(false); } catch (Exception ex) { string error = await _Validation.HandleException(ex, ErrorResponse.UpdateErrorMessage); throw new Exception(error); } } public async Task DeleteCustomerProductMatrixCell(int customerProductMatrixCellId, LoginDTO loginDTO, CancellationToken ct) { try { int result = await _QueryExecutor .ExecuteAsync(loginDTO, CustomerProductMatrixCellQB.DELETE_CUSTOMERPRODUCTMATRIXCELL, new { CustomerProductMatrixCellId = customerProductMatrixCellId }, 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); } } }