Merge pull request 'Implemented an API endpoint that allows the system to record attendance entries (e.g., check-in and check-out) for a specific employee. This helps track employee working hours, presence, and status.' (#37) from Ashutosh_Feature#183_Get_AttendanceLogs_By_EmployeeId into main
Reviewed-on: #37
This commit is contained in:
commit
0dc39e36d9
@ -67,22 +67,56 @@ namespace MarcoBMS.Services.Controllers
|
||||
return Ok(ApiResponse<object>.SuccessResponse(attendanceLogVMs, System.String.Format("{0} Attendance records fetched successfully", lstAttendance.Count), 200));
|
||||
|
||||
}
|
||||
[HttpGet("log/employee/{employeeid}")]
|
||||
[HttpGet("log/employee/{employeeId}")]
|
||||
|
||||
public async Task<IActionResult> GetAttendanceLogByEmployeeId(Guid employeeid, [FromQuery] string? date = null)
|
||||
public async Task<IActionResult> GetAttendanceLogByEmployeeId(Guid employeeId, [FromQuery] string? dateFrom = null, [FromQuery] string? dateTo = null)
|
||||
{
|
||||
Guid TenantId = GetTenantId();
|
||||
DateOnly forDate = new DateOnly();
|
||||
DateTime fromDate = new DateTime();
|
||||
DateTime toDate = new DateTime();
|
||||
|
||||
if (date != null && DateOnly.TryParse(date, out forDate) == false)
|
||||
if (dateFrom != null && DateTime.TryParse(dateFrom, out fromDate) == false)
|
||||
{
|
||||
_logger.LogError("User sent Invalid from Date while featching attendance logs");
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid Date", "Invalid Date", 400));
|
||||
}
|
||||
if (dateTo != null && DateTime.TryParse(dateTo, out toDate) == false)
|
||||
{
|
||||
_logger.LogError("User sent Invalid to Date while featching attendance logs");
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Invalid Date", "Invalid Date", 400));
|
||||
|
||||
}
|
||||
List<AttendanceLog> lstAttendance = await _context.AttendanceLogs.Where(c => c.EmployeeID == employeeid && c.TenantId == TenantId).ToListAsync();
|
||||
|
||||
_logger.LogInfo("{count} Attendance records fetched successfully", lstAttendance.Count);
|
||||
return Ok(ApiResponse<object>.SuccessResponse(lstAttendance, System.String.Format("{0} Attendance records fetched successfully", lstAttendance.Count), 200));
|
||||
if (employeeId == Guid.Empty)
|
||||
{
|
||||
_logger.LogError("The employee Id sent by user is empty");
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Employee ID is required and must not be Empty.", "Employee ID is required and must not be empty.", 400));
|
||||
}
|
||||
List<Attendance> attendances = await _context.Attendes.Where(c => c.EmployeeID == employeeId && c.TenantId == TenantId && c.AttendanceDate.Date >= fromDate && c.AttendanceDate.Date <= toDate).ToListAsync();
|
||||
Employee? employee = await _context.Employees.Include(e => e.JobRole).FirstOrDefaultAsync(e => e.Id == employeeId && e.TenantId == TenantId && e.IsActive);
|
||||
List<EmployeeAttendanceVM> results = new List<EmployeeAttendanceVM>();
|
||||
|
||||
if (employee != null)
|
||||
{
|
||||
foreach (var attendance in attendances)
|
||||
{
|
||||
EmployeeAttendanceVM result = new EmployeeAttendanceVM
|
||||
{
|
||||
Id = attendance.Id,
|
||||
EmployeeId = employee.Id,
|
||||
FirstName = employee.FirstName,
|
||||
LastName = employee.LastName,
|
||||
CheckInTime = attendance.InTime,
|
||||
CheckOutTime = attendance.OutTime,
|
||||
JobRoleName = employee.JobRole != null ? employee.JobRole.Name : "",
|
||||
Activity = attendance.Activity,
|
||||
EmployeeAvatar = null
|
||||
};
|
||||
results.Add(result);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInfo("{count} Attendance records fetched successfully", results.Count);
|
||||
return Ok(ApiResponse<object>.SuccessResponse(results, System.String.Format("{0} Attendance records fetched successfully", results.Count), 200));
|
||||
|
||||
|
||||
}
|
||||
@ -130,6 +164,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
|
||||
|
||||
List<ProjectAllocation> projectteam = await _projectsHelper.GetTeamByProject(TenantId, projectId, true);
|
||||
var jobRole = await _context.JobRoles.ToListAsync();
|
||||
foreach (Attendance? attendance in lstAttendance)
|
||||
{
|
||||
var result1 = new EmployeeAttendanceVM()
|
||||
@ -144,8 +179,18 @@ namespace MarcoBMS.Services.Controllers
|
||||
{
|
||||
result1.EmployeeAvatar = null;
|
||||
result1.EmployeeId = teamMember.EmployeeId;
|
||||
result1.FirstName = teamMember.Employee != null ? teamMember.Employee.FirstName : null;
|
||||
result1.LastName = teamMember.Employee != null ? teamMember.Employee.LastName : null;
|
||||
if (teamMember.Employee != null)
|
||||
{
|
||||
result1.FirstName = teamMember.Employee.FirstName;
|
||||
result1.LastName = teamMember.Employee.LastName;
|
||||
result1.JobRoleName = teamMember.Employee.JobRole != null ? teamMember.Employee.JobRole.Name : null;
|
||||
}
|
||||
else
|
||||
{
|
||||
result1.FirstName = null;
|
||||
result1.LastName = null;
|
||||
result1.JobRoleName = null;
|
||||
}
|
||||
|
||||
result.Add(result1);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user