Sending the project degination in place of employee degination in allocation history API

This commit is contained in:
ashutosh.nehete 2025-08-13 11:07:36 +05:30
parent 897a998b27
commit d113fc3c3d
3 changed files with 33 additions and 4 deletions

View File

@ -0,0 +1,11 @@
namespace Marco.Pms.Model.ViewModels.Projects
{
public class ProjectHisteryVM
{
public string? ProjectName { get; set; }
public string? ProjectShortName { get; set; }
public DateTime AssignedDate { get; set; }
public DateTime? RemovedDate { get; set; }
public string? Designation { get; set; }
}
}

View File

@ -918,17 +918,35 @@ namespace Marco.Pms.Services.Service
ProjectShortName = pa.Project.ShortName, ProjectShortName = pa.Project.ShortName,
AssignedDate = pa.AllocationDate, AssignedDate = pa.AllocationDate,
RemovedDate = pa.ReAllocationDate, RemovedDate = pa.ReAllocationDate,
Designation = pa.Employee!.JobRole!.Name Designation = pa.Employee!.JobRole!.Name,
DesignationId = pa.JobRoleId
}) })
.ToListAsync(); .ToListAsync();
var designationIds = projectAllocation.Select(pa => pa.DesignationId).ToList();
var designations = await _context.JobRoles.Where(jr => designationIds.Contains(jr.Id)).ToListAsync();
var response = projectAllocation.Select(pa =>
{
var designation = designations.FirstOrDefault(jr => jr.Id == pa.DesignationId);
return new ProjectHisteryVM
{
ProjectName = pa.ProjectName,
ProjectShortName = pa.ProjectShortName,
AssignedDate = pa.AssignedDate,
RemovedDate = pa.RemovedDate,
Designation = designation?.Name
};
}).ToList();
// Log successful retrieval including count of records // Log successful retrieval including count of records
_logger.LogInfo("Successfully fetched {Count} projects for EmployeeId: {EmployeeId}", _logger.LogInfo("Successfully fetched {Count} projects for EmployeeId: {EmployeeId}",
projectAllocation.Count, employeeId); projectAllocation.Count, employeeId);
return ApiResponse<object>.SuccessResponse( return ApiResponse<object>.SuccessResponse(
projectAllocation, response,
$"{projectAllocation.Count} project assignments fetched for employee.", $"{response.Count} project assignments fetched for employee.",
200); 200);
} }
catch (Exception ex) catch (Exception ex)

View File

@ -49,6 +49,6 @@
"MongoDB": { "MongoDB": {
"SerilogDatabaseUrl": "mongodb://localhost:27017/DotNetLogs", "SerilogDatabaseUrl": "mongodb://localhost:27017/DotNetLogs",
"ConnectionString": "mongodb://localhost:27017/MarcoBMS_Caches?socketTimeoutMS=500&serverSelectionTimeoutMS=500&connectTimeoutMS=500", "ConnectionString": "mongodb://localhost:27017/MarcoBMS_Caches?socketTimeoutMS=500&serverSelectionTimeoutMS=500&connectTimeoutMS=500",
"ModificationConnectionString": "mongodb://localhost:27017/ModificationLog?socketTimeoutMS=500&serverSelectionTimeoutMS=500&connectTimeoutMS=500" "ModificationConnectionString": "mongodb://localhost:27017/ModificationLog?socketTimeoutMS=500&serverSelectionTimeoutMS=500&connectTimeoutMS=500&replicaSet=rs01&directConnection=true"
} }
} }