From 499fc9e69e56361adc2ba4ff5be2bc98451febf6 Mon Sep 17 00:00:00 2001 From: "ashutosh.nehete" Date: Tue, 29 Apr 2025 17:26:29 +0530 Subject: [PATCH] When requesting regularization, ensure that the check-out time is later than the check-in time. --- .../Controllers/AttendanceController.cs | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) 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)); } } -- 2.43.0