diff --git a/Marco.Pms.Services/Controllers/AttendanceController.cs b/Marco.Pms.Services/Controllers/AttendanceController.cs index 81a0f30..e1dda01 100644 --- a/Marco.Pms.Services/Controllers/AttendanceController.cs +++ b/Marco.Pms.Services/Controllers/AttendanceController.cs @@ -336,8 +336,16 @@ namespace MarcoBMS.Services.Controllers { DateTime date = attendance.AttendanceDate; finalDateTime = GetDateFromTimeStamp(date.Date, recordAttendanceDot.MarkTime); - attendance.OutTime = finalDateTime; - attendance.Activity = ATTENDANCE_MARK_TYPE.REQUEST_REGULARIZE; + if (attendance.InTime < finalDateTime) + { + attendance.OutTime = finalDateTime; + attendance.Activity = ATTENDANCE_MARK_TYPE.REQUEST_REGULARIZE; + } + else + { + _logger.LogError("Employee {EmployeeId} sent regularization request but it check-out time is earlier than check-out"); + return BadRequest(ApiResponse.ErrorResponse("Check-out time must be later than check-in time", "Check-out time must be later than check-in time", 400)); + } // do nothing } else if (recordAttendanceDot.Action == ATTENDANCE_MARK_TYPE.REGULARIZE) @@ -433,7 +441,13 @@ namespace MarcoBMS.Services.Controllers { await transaction.RollbackAsync(); // Rollback on failure _logger.LogError("{Error} while marking attendance", ex.Message); - return BadRequest(ApiResponse.ErrorResponse(ex.Message, ex, 400)); + var response = new + { + message = ex.Message, + detail = ex.StackTrace, + statusCode = StatusCodes.Status500InternalServerError + }; + return BadRequest(ApiResponse.ErrorResponse(ex.Message, response, 400)); } } @@ -495,8 +509,16 @@ namespace MarcoBMS.Services.Controllers { DateTime date = attendance.AttendanceDate; finalDateTime = GetDateFromTimeStamp(date.Date, recordAttendanceDot.MarkTime); - attendance.OutTime = finalDateTime; - attendance.Activity = ATTENDANCE_MARK_TYPE.REQUEST_REGULARIZE; + if (attendance.InTime < finalDateTime) + { + attendance.OutTime = finalDateTime; + attendance.Activity = ATTENDANCE_MARK_TYPE.REQUEST_REGULARIZE; + } + else + { + _logger.LogError("Employee {EmployeeId} sent regularization request but it check-out time is earlier than check-out"); + return BadRequest(ApiResponse.ErrorResponse("Check-out time must be later than check-in time", "Check-out time must be later than check-in time", 400)); + } // do nothing } else if (recordAttendanceDot.Action == ATTENDANCE_MARK_TYPE.REGULARIZE) @@ -668,7 +690,13 @@ namespace MarcoBMS.Services.Controllers { await transaction.RollbackAsync(); // Rollback on failure _logger.LogError("{Error} while marking attendance", ex.Message); - return BadRequest(ApiResponse.ErrorResponse(ex.Message, ex, 400)); + var response = new + { + message = ex.Message, + detail = ex.StackTrace, + statusCode = StatusCodes.Status500InternalServerError + }; + return BadRequest(ApiResponse.ErrorResponse(ex.Message, response, 400)); } }