using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using GB5Shared.Validation; using RecruitmentDAL.DTO.CandidateDemographic; using RecruitmentDAL.Query.CandidateDemographic; using System; using System.Data.Common; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace RecruitmentDAL.CustomeCode.CandidateDemographic { public class CandidateDemographicDAL : ICandidateDemographicDAL { private readonly IQueryExecutor _QueryExecutor; private readonly IValidation _Validation; public CandidateDemographicDAL( IQueryExecutor queryExecutor, IValidation validation) { _QueryExecutor = queryExecutor; _Validation = validation; } #region Get public async Task GetByCandidateId(int CandidateId, LoginDTO LoginDTO, CancellationToken ct) { var parameters = new { CandidateId = CandidateId, TenantId = LoginDTO.ClientId }; var result = await _QueryExecutor .QueryAsync(LoginDTO, CandidateDemographicQB.GET_BY_CANDIDATEID, parameters, cancellationToken: ct) .ConfigureAwait(false); return result.FirstOrDefault(); } #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 SaveCandidateDemographic(CandidateDemographicDTO CandidateDemographicDTO, LoginDTO LoginDTO, DbTransaction tx, CancellationToken ct) { try { const string sql = CandidateDemographicQB.SAVE_CANDIDATEDEMOGRAPHIC; return await _QueryExecutor .ExecuteAsync(LoginDTO, sql, CandidateDemographicDTO, 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 UpdateCandidateDemographic(CandidateDemographicDTO CandidateDemographicDTO, LoginDTO LoginDTO, DbTransaction tx, CancellationToken ct) { try { const string sql = CandidateDemographicQB.UPDATE_CANDIDATEDEMOGRAPHIC; return await _QueryExecutor .ExecuteAsync(LoginDTO, sql, CandidateDemographicDTO, 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 DeleteCandidateDemographic(int CandidateDemographicId, LoginDTO LoginDTO, CancellationToken ct) { try { string sql = CandidateDemographicQB.DELETE_CANDIDATEDEMOGRAPHIC; var parameter = new { CandidateDemographicId = CandidateDemographicId, 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 } }