From 00b59d249994118b2010fff3f0734518e869dae0 Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Sat, 13 Dec 2025 15:27:50 +0530 Subject: [PATCH] Added Jobrole name in get project allocation API VM --- Marco.Pms.Services/Service/ProjectServices.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Marco.Pms.Services/Service/ProjectServices.cs b/Marco.Pms.Services/Service/ProjectServices.cs index 304132d..62d4ba4 100644 --- a/Marco.Pms.Services/Service/ProjectServices.cs +++ b/Marco.Pms.Services/Service/ProjectServices.cs @@ -894,6 +894,8 @@ namespace Marco.Pms.Services.Service return ApiResponse.ErrorResponse("Access Denied.", "You do not have permission to view this project's team.", 403); } + var jobRoles = await _context.JobRoles.AsNoTracking().Where(jr => jr.TenantId == tenantId).ToListAsync(); + // --- Step 3: Execute a Single, Optimized Database Query --- // This query projects directly to a new object on the database server, which is highly efficient. var projectAllocationQuery = _context.ProjectAllocations @@ -924,7 +926,7 @@ namespace Marco.Pms.Services.Service } var allocations = await projectAllocationQuery - .Where(pa => pa.Service != null) + .Where(pa => pa.Service != null && pa.Employee != null) .Select(pa => new { // Fields from ProjectAllocation @@ -947,7 +949,8 @@ namespace Marco.Pms.Services.Service ServiceName = pa.Service!.Name, // Simplified JobRoleId logic: Use the allocation's role if it exists, otherwise fall back to the employee's default role. - JobRoleId = pa.JobRoleId ?? pa.Employee.JobRoleId + JobRoleId = pa.JobRoleId ?? pa.Employee.JobRoleId, + JobRoleName = jobRoles.Where(jr => jr.Id == pa.JobRoleId).Select(jr => jr.Name).FirstOrDefault() ?? pa.Employee.JobRole!.Name }) .ToListAsync();