Passing role name in record attendance api

This commit is contained in:
ashutosh.nehete 2025-04-09 10:41:00 +05:30
parent 56448cb8a2
commit e41faf4045
2 changed files with 19 additions and 13 deletions

View File

@ -278,7 +278,7 @@ namespace MarcoBMS.Services.Controllers
DateTime finalDateTime = GetDateFromTimeStamp(recordAttendanceDot, recordAttendanceDot.MarkTime); DateTime finalDateTime = GetDateFromTimeStamp(recordAttendanceDot, recordAttendanceDot.MarkTime);
//if(recordAttendanceDot.Comment != null)
if (attendance != null) if (attendance != null)
{ {
attendance.Comment = recordAttendanceDot.Comment; attendance.Comment = recordAttendanceDot.Comment;
@ -372,19 +372,24 @@ namespace MarcoBMS.Services.Controllers
await transaction.CommitAsync(); // Commit transaction await transaction.CommitAsync(); // Commit transaction
Employee employee = await _employeeHelper.GetEmployeeByID(recordAttendanceDot.EmployeeID); Employee employee = await _employeeHelper.GetEmployeeByID(recordAttendanceDot.EmployeeID);
EmployeeAttendanceVM vm = new EmployeeAttendanceVM() if(employee.JobRole != null)
{ {
CheckInTime = attendance.InTime, EmployeeAttendanceVM vm = new EmployeeAttendanceVM()
CheckOutTime = attendance.OutTime, {
EmployeeAvatar = null, CheckInTime = attendance.InTime,
EmployeeId = recordAttendanceDot.EmployeeID, CheckOutTime = attendance.OutTime,
FirstName = employee.FirstName, EmployeeAvatar = null,
LastName = employee.LastName, EmployeeId = recordAttendanceDot.EmployeeID,
Id = attendance.Id, FirstName = employee.FirstName,
Activity = attendance.Activity LastName = employee.LastName,
}; Id = attendance.Id,
Activity = attendance.Activity,
JobRoleName = employee.JobRole.Name
};
return Ok(ApiResponse<object>.SuccessResponse(vm, "Attendance marked successfully.", 200)); return Ok(ApiResponse<object>.SuccessResponse(vm, "Attendance marked successfully.", 200));
}
return Ok(ApiResponse<object>.SuccessResponse(new EmployeeAttendanceVM(), "Attendance marked successfully.", 200));
} }
catch (Exception ex) catch (Exception ex)

View File

@ -18,7 +18,8 @@ namespace MarcoBMS.Services.Helpers
} }
public async Task<Employee> GetEmployeeByID(int EmployeeID) public async Task<Employee> GetEmployeeByID(int EmployeeID)
{ {
return await _context.Employees.FindAsync(EmployeeID);
return await _context.Employees.Include(e => e.JobRole).FirstOrDefaultAsync(e => e.Id == EmployeeID) ?? new Employee { };
} }
public async Task<Employee> GetEmployeeByApplicationUserID(string ApplicationUserID) public async Task<Employee> GetEmployeeByApplicationUserID(string ApplicationUserID)