Added organizationId filter to the employee list for organization assiged to the project

This commit is contained in:
ashutosh.nehete 2025-09-26 11:43:44 +05:30
parent eddbdde355
commit f2213db807

View File

@ -123,7 +123,7 @@ namespace MarcoBMS.Services.Controllers
}
[HttpGet("list/organizations/{projectId}")]
public async Task<IActionResult> GetEmployeesByProjectAsync(Guid projectId, [FromQuery] string searchString)
public async Task<IActionResult> GetEmployeesByProjectAsync(Guid projectId, [FromQuery] string searchString, [FromQuery] Guid? organizationId)
{
try
{
@ -179,10 +179,17 @@ namespace MarcoBMS.Services.Controllers
}
// Fetch employees allocated to the project matching the search criteria
var employees = await _context.Employees
var employeesQuery = _context.Employees
.AsNoTracking() // Improves performance by disabling change tracking for read-only query
.Include(e => e.JobRole)
.Where(e => (e.FirstName + " " + e.LastName).Contains(searchString) && organizationIds.Contains(e.OrganizationId))
.Where(e => (e.FirstName + " " + e.LastName).Contains(searchString) && organizationIds.Contains(e.OrganizationId));
if (organizationId.HasValue)
{
employeesQuery = employeesQuery.Where(e => e.OrganizationId == organizationId);
}
var employees = await employeesQuery
.ToListAsync();
var result = employees.Select(e => _mapper.Map<EmployeeVM>(e)).Distinct().ToList();