using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using TCMSDAL.DTO; using TCMSDAL.Interfaces; using TCMSDAL.QueryBuilders; namespace TCMSDAL.Implementations; /// /// Read/write DAL for MTCMSPROJECT. /// Multi-tenant: all queries filter by TenantId from LoginDTO. /// public class TCMSProjectDAL : ITCMSProjectDAL { private readonly IQueryExecutor _QueryExecutor; public TCMSProjectDAL(IQueryExecutor queryExecutor) { _QueryExecutor = queryExecutor; } public async Task GetProjectAsync( int projectId, LoginDTO login, CancellationToken ct) => await _QueryExecutor.QuerySingleAsync( login, TCMSProjectQB.GET_PROJECT, new { ProjectId = projectId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); public async Task> GetProjectListAsync( string? projectType, string? status, bool? isActive, LoginDTO login, CancellationToken ct) => await _QueryExecutor.QueryAsync( login, TCMSProjectQB.GET_PROJECT_LIST, new { TenantId = login.ClientId, ProjectType = projectType, Status = status, IsActive = isActive }, cancellationToken: ct).ConfigureAwait(false) ?? Enumerable.Empty(); public async Task> GetSelectListAsync( LoginDTO login, CancellationToken ct) => await _QueryExecutor.QueryAsync( login, TCMSProjectQB.GET_SELECT_LIST, new { TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false) ?? Enumerable.Empty(); public async Task SaveProjectAsync( TCMSProjectDTO dto, LoginDTO login, CancellationToken ct) => await _QueryExecutor.ExecuteIdentityAsync( login, TCMSProjectQB.SAVE_PROJECT, new { dto.ProjectCode, dto.ProjectName, dto.Description, dto.ProjectType, dto.ClientId, dto.ProductId, dto.Status, dto.LeadConsultant, dto.StartDate, dto.GoLiveDate, TenantId = login.ClientId, CreatedBy = login.UserId }).ConfigureAwait(false); public async Task UpdateProjectAsync( TCMSProjectDTO dto, LoginDTO login, CancellationToken ct) => await _QueryExecutor.ExecuteAsync( login, TCMSProjectQB.UPDATE_PROJECT, new { dto.ProjectId, dto.ProjectName, dto.Description, dto.ProjectType, dto.ClientId, dto.ProductId, dto.Status, dto.LeadConsultant, dto.StartDate, dto.GoLiveDate, dto.IsActive, TenantId = login.ClientId, ModifiedBy = login.UserId }, cancellationToken: ct).ConfigureAwait(false); public async Task CodeExistsAsync( string code, int? projectId, LoginDTO login, CancellationToken ct) { int count = await _QueryExecutor.ExecuteScalarAsync( login, TCMSProjectQB.CHECK_CODE_EXISTS, new { ProjectCode = code, ProjectId = projectId, TenantId = login.ClientId }, cancellationToken: ct).ConfigureAwait(false); return count > 0; } }