diff --git a/Marco.Pms.Model/ViewModels/Projects/ProjectHisteryVM.cs b/Marco.Pms.Model/ViewModels/Projects/ProjectHisteryVM.cs new file mode 100644 index 0000000..4df0480 --- /dev/null +++ b/Marco.Pms.Model/ViewModels/Projects/ProjectHisteryVM.cs @@ -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; } + } +} \ No newline at end of file diff --git a/Marco.Pms.Services/Service/ProjectServices.cs b/Marco.Pms.Services/Service/ProjectServices.cs index 0b95cb4..6cb7e68 100644 --- a/Marco.Pms.Services/Service/ProjectServices.cs +++ b/Marco.Pms.Services/Service/ProjectServices.cs @@ -918,17 +918,35 @@ namespace Marco.Pms.Services.Service ProjectShortName = pa.Project.ShortName, AssignedDate = pa.AllocationDate, RemovedDate = pa.ReAllocationDate, - Designation = pa.Employee!.JobRole!.Name + Designation = pa.Employee!.JobRole!.Name, + DesignationId = pa.JobRoleId }) .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 _logger.LogInfo("Successfully fetched {Count} projects for EmployeeId: {EmployeeId}", projectAllocation.Count, employeeId); return ApiResponse.SuccessResponse( - projectAllocation, - $"{projectAllocation.Count} project assignments fetched for employee.", + response, + $"{response.Count} project assignments fetched for employee.", 200); } catch (Exception ex) diff --git a/Marco.Pms.Services/appsettings.Development.json b/Marco.Pms.Services/appsettings.Development.json index 579b059..4bb9519 100644 --- a/Marco.Pms.Services/appsettings.Development.json +++ b/Marco.Pms.Services/appsettings.Development.json @@ -49,6 +49,6 @@ "MongoDB": { "SerilogDatabaseUrl": "mongodb://localhost:27017/DotNetLogs", "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" } }