using CMGMDAL.DTOs; using CMGMDAL.Interfaces; using CMGMDAL.QueryBuilders; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; namespace CMGMDAL.Implementations; public class CareerPathDAL : ICareerPathDAL { private readonly IQueryExecutor _qe; public CareerPathDAL(IQueryExecutor queryExecutor) => _qe = queryExecutor; public async Task GetByIdAsync(int careerPathId, LoginDTO login, CancellationToken ct) => await _qe.QuerySingleAsync(login, CareerPathQB.GET_BY_ID, new { CareerPathId = careerPathId, TenantId = login.ClientId }) .ConfigureAwait(false); public async Task> GetListAsync(int frameworkId, short status, LoginDTO login, CancellationToken ct) => await _qe.QueryAsync(login, CareerPathQB.GET_LIST, new { FrameworkId = frameworkId, Status = status, TenantId = login.ClientId }, cancellationToken: ct) .ConfigureAwait(false) ?? Enumerable.Empty(); public async Task> GetByCurrentRoleAsync(int currentRoleId, LoginDTO login, CancellationToken ct) => await _qe.QueryAsync(login, CareerPathQB.GET_BY_CURRENT_ROLE, new { CurrentRoleId = currentRoleId, TenantId = login.ClientId }, cancellationToken: ct) .ConfigureAwait(false) ?? Enumerable.Empty(); public async Task SaveAsync(CareerPathDTO dto, bool isNew, LoginDTO login, CancellationToken ct) { if (isNew) return await _qe.ExecuteIdentityAsync(login, CareerPathQB.INSERT, new { dto.FrameworkId, dto.PathCode, dto.PathName, dto.CurrentRoleId, dto.TargetRoleId, dto.TypicalMonthsRequired, dto.Description, dto.Status, TenantId = login.ClientId, CreatedBy = login.UserId, ModifiedBy = login.UserId }) .ConfigureAwait(false); await _qe.ExecuteAsync(login, CareerPathQB.UPDATE, new { dto.CareerPathId, dto.PathCode, dto.PathName, dto.CurrentRoleId, dto.TargetRoleId, dto.TypicalMonthsRequired, dto.Description, dto.Status, TenantId = login.ClientId, ModifiedBy = login.UserId }, cancellationToken: ct).ConfigureAwait(false); return dto.CareerPathId; } public async Task DeleteAsync(int careerPathId, LoginDTO login, CancellationToken ct) => await _qe.ExecuteAsync(login, CareerPathQB.DELETE, new { CareerPathId = careerPathId, TenantId = login.ClientId }, cancellationToken: ct) .ConfigureAwait(false); public async Task> GetRequirementsAsync(int careerPathId, LoginDTO login, CancellationToken ct) => await _qe.QueryAsync(login, CareerPathQB.GET_REQUIREMENTS, new { CareerPathId = careerPathId, TenantId = login.ClientId }, cancellationToken: ct) .ConfigureAwait(false) ?? Enumerable.Empty(); public async Task SaveRequirementAsync(CareerPathRequirementDTO dto, bool isNew, LoginDTO login, CancellationToken ct) { if (isNew) return await _qe.ExecuteIdentityAsync(login, CareerPathQB.INSERT_REQUIREMENT, new { dto.CareerPathId, dto.SkillId, dto.MinProficiencyLevel, dto.IsMandatory, dto.SortOrder, TenantId = login.ClientId }) .ConfigureAwait(false); await _qe.ExecuteAsync(login, CareerPathQB.UPDATE_REQUIREMENT, new { dto.CareerPathReqId, dto.MinProficiencyLevel, dto.IsMandatory, dto.SortOrder, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); return dto.CareerPathReqId; } public async Task DeleteRequirementAsync(int careerPathReqId, LoginDTO login, CancellationToken ct) => await _qe.ExecuteAsync(login, CareerPathQB.DELETE_REQUIREMENT, new { CareerPathReqId = careerPathReqId, TenantId = login.ClientId }, cancellationToken: ct) .ConfigureAwait(false); }