using RecruitmentDAL.DTO.JobProfile; using RecruitmentDAL.Query.JobProfile; using GB5Shared.DTO.Framework.Criteria; 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.JobProfile { public class JobProfileDAL : IJobProfileDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public JobProfileDAL( IQueryExecutor queryExecutor, IValidation validation) { _QueryExecutor = queryExecutor; _Validation = validation; } #region Get public async Task GetJobProfile(int JobProfileId, LoginDTO LoginDTO, CancellationToken ct) { try { string sql = JobProfileQB.GET_JOBPROFILE; var parameters = new { jobProfileid = JobProfileId }; JobProfileDTO result = await _QueryExecutor .QuerySingleAsync(LoginDTO, sql, parameters, cancellationToken: ct) .ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch { throw; } } #endregion #region Select List public async Task GetSelectListJobProfile(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO, CancellationToken ct) { try { string sql = JobProfileQB.GET_SELECTLIST_JOBPROFILE; var result = await _QueryExecutor .QueryAsync(LoginDTO, sql, null!, 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 SaveJobProfile(JobProfileDTO JobProfileDTO, LoginDTO LoginDTO, DbTransaction tx, CancellationToken ct) { try { const string sql = JobProfileQB.SAVE_JOBPROFILE; return await _QueryExecutor .ExecuteAsync(LoginDTO, sql, JobProfileDTO, 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 UpdateJobProfile(JobProfileDTO JobProfileDTO, LoginDTO LoginDTO, DbTransaction tx, CancellationToken ct) { try { const string sql = JobProfileQB.UPDATE_JOBPROFILE; return await _QueryExecutor .ExecuteAsync(LoginDTO, sql, JobProfileDTO, 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 DeleteJobProfile(int JobProfileId, LoginDTO LoginDTO, CancellationToken ct) { try { string sql = JobProfileQB.DELETE_JOBPROFILE; var parameter = new { jobProfileid = JobProfileId }; 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 #region Get public async Task GetJobProfileDetail(int JobProfileDetailId, LoginDTO LoginDTO, CancellationToken ct) { try { string sql = JobProfileQB.GET_JOBPROFILEDETAIL; var parameters = new { jobProfileDetailId = JobProfileDetailId }; JobProfileDetailDTO result = await _QueryExecutor .QuerySingleAsync(LoginDTO, sql, parameters, cancellationToken: ct) .ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch { throw; } } #endregion #region Select List public async Task GetSelectListJobProfileDetail(CriteriaDTO CriteriaDTO, LoginDTO LoginDTO, CancellationToken ct) { try { string sql = JobProfileQB.GET_SELECTLIST_JOBPROFILEDETAIL; var result = await _QueryExecutor .QueryAsync(LoginDTO, sql, null!, cancellationToken: ct) .ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch { throw; } } #endregion #region Save public async Task SaveJobProfileDetail(JobProfileDetailDTO JobProfileDetailDTO, LoginDTO LoginDTO, DbTransaction tx, CancellationToken ct) { try { const string sql = JobProfileQB.SAVE_JOBPROFILEDETAIL; return await _QueryExecutor .ExecuteAsync(LoginDTO, sql, JobProfileDetailDTO, 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 UpdateJobProfileDetail(JobProfileDetailDTO JobProfileDetailDTO, LoginDTO LoginDTO, DbTransaction tx, CancellationToken ct) { try { const string sql = JobProfileQB.UPDATE_JOBPROFILEDETAIL; return await _QueryExecutor .ExecuteAsync(LoginDTO, sql, JobProfileDetailDTO, 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 DeleteJobProfileDetail(int JobProfileDetailId, LoginDTO LoginDTO, CancellationToken ct) { try { string sql = JobProfileQB.DELETE_JOBPROFILEDETAIL; var parameter = new { jobProfileDetailId = JobProfileDetailId }; 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 } }