using RecruitmentDAL.DTO.JobAdSpend; using RecruitmentDAL.Query.JobAdSpend; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.Validation; using Newtonsoft.Json; using System; using System.Data.Common; using System.Threading; using System.Threading.Tasks; namespace RecruitmentDAL.CustomeCode.JobAdSpend { public class JobAdSpendDAL : IJobAdSpendDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public JobAdSpendDAL( IQueryExecutor queryExecutor, IValidation validation) { _QueryExecutor = queryExecutor; _Validation = validation; } #region Get public async Task GetJobAdSpend(int JobAdSpendId, LoginDTO LoginDTO, CancellationToken ct) { try { string sql = JobAdSpendQB.GET_JOBADSPEND; var parameters = new { JobAdSpendId = JobAdSpendId, TenantId = LoginDTO.ClientId }; JobAdSpendDTO dto = await _QueryExecutor .QuerySingleAsync(LoginDTO, sql, parameters, cancellationToken: ct) .ConfigureAwait(false); return JsonConvert.SerializeObject(dto); } catch { throw; } } #endregion #region Select List public async Task GetSelectListJobAdSpend(int JobRequisitionId, LoginDTO LoginDTO, CancellationToken ct) { try { string sql = JobAdSpendQB.GET_SELECTLIST_JOBADSPEND_BY_JOBREQUISITION; var parameters = new { JobRequisitionId = JobRequisitionId, TenantId = LoginDTO.ClientId }; var result = await _QueryExecutor .QueryAsync(LoginDTO, sql, parameters, cancellationToken: ct) .ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch { throw; } } #endregion #region Save // Called from BaseEntityAppService.ExecuteSaveAsync's persistFunc — must run on the // pipeline's own transaction (tx) so validation/workflow/event-publish/outbox all commit // or roll back atomically with the insert. public async Task SaveJobAdSpend(JobAdSpendDTO JobAdSpendDTO, LoginDTO LoginDTO, DbTransaction tx, CancellationToken ct) { try { const string sql = JobAdSpendQB.SAVE_JOBADSPEND; return await _QueryExecutor .ExecuteAsync(LoginDTO, sql, JobAdSpendDTO, tx, ct) .ConfigureAwait(false); } catch (Exception ex) { string error = await _Validation.HandleException(ex, ErrorResponse.SaveErrorMessage); throw new Exception(error); } } #endregion #region Update public async Task UpdateJobAdSpend(JobAdSpendDTO JobAdSpendDTO, LoginDTO LoginDTO, DbTransaction tx, CancellationToken ct) { try { const string sql = JobAdSpendQB.UPDATE_JOBADSPEND; return await _QueryExecutor .ExecuteAsync(LoginDTO, sql, JobAdSpendDTO, tx, ct) .ConfigureAwait(false); } catch (Exception ex) { string error = await _Validation.HandleException(ex, ErrorResponse.UpdateErrorMessage); throw new Exception(error); } } #endregion #region Delete public async Task DeleteJobAdSpend(int JobAdSpendId, LoginDTO LoginDTO, CancellationToken ct) { try { string sql = JobAdSpendQB.DELETE_JOBADSPEND; var parameter = new { JobAdSpendId = JobAdSpendId, TenantId = LoginDTO.ClientId, ModifiedById = LoginDTO.UserId, ModifiedOn = DateTime.UtcNow }; int result = await _QueryExecutor .ExecuteAsync(LoginDTO, sql, parameter, 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); } } #endregion } }