Compare commits
5 Commits
Feature_Pl
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| d04af2747b | |||
| 89c529695c | |||
| b8c10a20bf | |||
| 00b59d2499 | |||
| 55a05ecff2 |
@ -894,6 +894,8 @@ 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
|
||||
@ -924,7 +926,10 @@ namespace Marco.Pms.Services.Service
|
||||
}
|
||||
|
||||
var allocations = await projectAllocationQuery
|
||||
.Where(pa => pa.Service != null)
|
||||
.Where(pa => pa.Service != null && pa.Employee != null)
|
||||
.ToListAsync();
|
||||
|
||||
var response = allocations
|
||||
.Select(pa => new
|
||||
{
|
||||
// Fields from ProjectAllocation
|
||||
@ -947,13 +952,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
|
||||
})
|
||||
.ToListAsync();
|
||||
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();
|
||||
|
||||
_logger.LogInfo("Successfully fetched {AllocationCount} allocations for project {ProjectId}.", allocations.Count, projectId);
|
||||
_logger.LogInfo("Successfully fetched {AllocationCount} allocations for project {ProjectId}.", response.Count, projectId);
|
||||
|
||||
return ApiResponse<object>.SuccessResponse(allocations, "Project allocations retrieved successfully.", 200);
|
||||
return ApiResponse<object>.SuccessResponse(response, "Project allocations retrieved successfully.", 200);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user