Compare commits
No commits in common. "main" and "Feature_Plan_Review" have entirely different histories.
main
...
Feature_Pl
@ -894,8 +894,6 @@ namespace Marco.Pms.Services.Service
|
||||
return ApiResponse<object>.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
|
||||
@ -926,10 +924,7 @@ namespace Marco.Pms.Services.Service
|
||||
}
|
||||
|
||||
var allocations = await projectAllocationQuery
|
||||
.Where(pa => pa.Service != null && pa.Employee != null)
|
||||
.ToListAsync();
|
||||
|
||||
var response = allocations
|
||||
.Where(pa => pa.Service != null)
|
||||
.Select(pa => new
|
||||
{
|
||||
// Fields from ProjectAllocation
|
||||
@ -952,13 +947,13 @@ 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,
|
||||
JobRoleName = jobRoles.Where(jr => jr.Id == (pa.JobRoleId ?? pa.Employee.JobRoleId)).Select(jr => jr.Name).FirstOrDefault() ?? pa.Employee.JobRole!.Name
|
||||
}).ToList();
|
||||
JobRoleId = pa.JobRoleId ?? pa.Employee.JobRoleId
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
_logger.LogInfo("Successfully fetched {AllocationCount} allocations for project {ProjectId}.", response.Count, projectId);
|
||||
_logger.LogInfo("Successfully fetched {AllocationCount} allocations for project {ProjectId}.", allocations.Count, projectId);
|
||||
|
||||
return ApiResponse<object>.SuccessResponse(response, "Project allocations retrieved successfully.", 200);
|
||||
return ApiResponse<object>.SuccessResponse(allocations, "Project allocations retrieved successfully.", 200);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user