Added Jobrole name in get project allocation API VM
This commit is contained in:
parent
cf240ae626
commit
00b59d2499
@ -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);
|
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 ---
|
// --- Step 3: Execute a Single, Optimized Database Query ---
|
||||||
// This query projects directly to a new object on the database server, which is highly efficient.
|
// This query projects directly to a new object on the database server, which is highly efficient.
|
||||||
var projectAllocationQuery = _context.ProjectAllocations
|
var projectAllocationQuery = _context.ProjectAllocations
|
||||||
@ -924,7 +926,7 @@ namespace Marco.Pms.Services.Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
var allocations = await projectAllocationQuery
|
var allocations = await projectAllocationQuery
|
||||||
.Where(pa => pa.Service != null)
|
.Where(pa => pa.Service != null && pa.Employee != null)
|
||||||
.Select(pa => new
|
.Select(pa => new
|
||||||
{
|
{
|
||||||
// Fields from ProjectAllocation
|
// Fields from ProjectAllocation
|
||||||
@ -947,7 +949,8 @@ namespace Marco.Pms.Services.Service
|
|||||||
ServiceName = pa.Service!.Name,
|
ServiceName = pa.Service!.Name,
|
||||||
|
|
||||||
// Simplified JobRoleId logic: Use the allocation's role if it exists, otherwise fall back to the employee's default role.
|
// 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();
|
.ToListAsync();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user