Merge branch 'Collection_Management' of https://git.marcoaiot.com/admin/marco.pms.api into Collection_Management
This commit is contained in:
commit
b3595ad6b6
@ -513,7 +513,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
{
|
||||
DateTime date = attendance.AttendanceDate;
|
||||
finalDateTime = GetDateFromTimeStamp(date.Date, recordAttendanceDot.MarkTime);
|
||||
if (attendance.InTime < finalDateTime)
|
||||
if (attendance.InTime <= finalDateTime)
|
||||
{
|
||||
attendance.OutTime = finalDateTime;
|
||||
attendance.Activity = ATTENDANCE_MARK_TYPE.REQUEST_REGULARIZE;
|
||||
|
@ -206,7 +206,6 @@ namespace MarcoBMS.Services.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("list/{projectId?}")]
|
||||
public async Task<IActionResult> GetEmployeesByProjectAsync(Guid? projectId, [FromQuery] bool showInactive = false)
|
||||
{
|
||||
@ -327,7 +326,6 @@ namespace MarcoBMS.Services.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("basic")]
|
||||
public async Task<IActionResult> GetEmployeesByProjectBasic(Guid? projectId, [FromQuery] string? searchString, [FromQuery] bool allEmployee)
|
||||
{
|
||||
@ -447,7 +445,6 @@ namespace MarcoBMS.Services.Controllers
|
||||
200));
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
[Route("profile/get/{employeeId}")]
|
||||
public async Task<IActionResult> GetEmployeeProfileById(Guid employeeId)
|
||||
@ -472,7 +469,6 @@ namespace MarcoBMS.Services.Controllers
|
||||
return _userHelper.GetTenantId();
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("old/manage")]
|
||||
public async Task<IActionResult> CreateUser([FromBody] CreateUserDto model)
|
||||
{
|
||||
@ -802,7 +798,6 @@ namespace MarcoBMS.Services.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("manage-mobile")]
|
||||
public async Task<IActionResult> CreateUserMoblie([FromBody] MobileUserManageDto model)
|
||||
{
|
||||
@ -1076,15 +1071,15 @@ namespace MarcoBMS.Services.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> SuspendEmployee(Guid id, [FromQuery] bool active = false)
|
||||
{
|
||||
using var scope = _serviceScopeFactory.CreateScope();
|
||||
|
||||
Guid tenantId = _userHelper.GetTenantId();
|
||||
var LoggedEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
Employee? employee = await _context.Employees.FirstOrDefaultAsync(e => e.Id == id && e.TenantId == tenantId);
|
||||
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||
|
||||
Employee? employee = await _context.Employees.FirstOrDefaultAsync(e => e.Id == id && e.OrganizationId == organizationId);
|
||||
if (employee == null)
|
||||
{
|
||||
_logger.LogWarning("Employee with ID {EmploueeId} not found in database", id);
|
||||
@ -1092,7 +1087,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
}
|
||||
if (employee.IsSystem)
|
||||
{
|
||||
_logger.LogWarning("Employee with ID {LoggedEmployeeId} tries to suspend system-defined employee with ID {EmployeeId}", LoggedEmployee.Id, employee.Id);
|
||||
_logger.LogWarning("Employee with ID {LoggedEmployeeId} tries to suspend system-defined employee with ID {EmployeeId}", loggedInEmployee.Id, employee.Id);
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("System-defined employees cannot be suspended.", "System-defined employees cannot be suspended.", 400));
|
||||
}
|
||||
var assignedToTasks = await _context.TaskMembers.Where(t => t.EmployeeId == employee.Id).ToListAsync();
|
||||
@ -1112,11 +1107,12 @@ namespace MarcoBMS.Services.Controllers
|
||||
}
|
||||
}
|
||||
var attendance = await _context.Attendes.Where(a => a.EmployeeId == employee.Id && (a.OutTime == null || a.Activity == ATTENDANCE_MARK_TYPE.REQUEST_REGULARIZE)).ToListAsync();
|
||||
if (attendance.Count != 0)
|
||||
if (attendance.Count != 0 && !active)
|
||||
{
|
||||
_logger.LogWarning("Employee with ID {EmployeeId} have any pending check-out or regularization requests", employee.Id);
|
||||
return BadRequest(ApiResponse<object>.ErrorResponse("Employee have any pending check-out or regularization requests", "Employee have any pending check-out or regularization requests", 400));
|
||||
}
|
||||
EmployeeVM employeeVM = new EmployeeVM();
|
||||
if (active)
|
||||
{
|
||||
employee.IsActive = true;
|
||||
@ -1128,6 +1124,7 @@ namespace MarcoBMS.Services.Controllers
|
||||
|
||||
}
|
||||
_logger.LogInfo("Employee with ID {EmployeId} Actived successfully", employee.Id);
|
||||
employeeVM = _mapper.Map<EmployeeVM>(employee);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1166,18 +1163,6 @@ namespace MarcoBMS.Services.Controllers
|
||||
}
|
||||
_logger.LogInfo("Employee with ID {EmployeId} Deleted successfully", employee.Id);
|
||||
|
||||
var _firebase = scope.ServiceProvider.GetRequiredService<IFirebaseService>();
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
// --- Push Notification Section ---
|
||||
// This section attempts to send a test push notification to the user's device.
|
||||
// It's designed to fail gracefully and handle invalid Firebase Cloud Messaging (FCM) tokens.
|
||||
|
||||
await _firebase.SendEmployeeSuspendMessageAsync(employee.Id, tenantId);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
try
|
||||
{
|
||||
@ -1188,10 +1173,22 @@ namespace MarcoBMS.Services.Controllers
|
||||
_logger.LogError(ex, "Exception Occured While activting/deactivting employee {EmployeeId}", employee.Id);
|
||||
return StatusCode(500, ApiResponse<object>.ErrorResponse("Internal Error Occured", "Error occured while saving the entity", 500));
|
||||
}
|
||||
var notification = new { LoggedInUserId = LoggedEmployee.Id, Keyword = "Employee", EmployeeId = employee.Id };
|
||||
var notification = new { LoggedInUserId = loggedInEmployee.Id, Keyword = "Employee", EmployeeId = employee.Id };
|
||||
|
||||
await _signalR.Clients.All.SendAsync("NotificationEventHandler", notification);
|
||||
return Ok(ApiResponse<object>.SuccessResponse(new { }, "Employee Suspended successfully", 200));
|
||||
|
||||
var _firebase = scope.ServiceProvider.GetRequiredService<IFirebaseService>();
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
// --- Push Notification Section ---
|
||||
// This section attempts to send a test push notification to the user's device.
|
||||
// It's designed to fail gracefully and handle invalid Firebase Cloud Messaging (FCM) tokens.
|
||||
|
||||
await _firebase.SendEmployeeSuspendMessageAsync(employee.Id, tenantId);
|
||||
|
||||
});
|
||||
return Ok(ApiResponse<object>.SuccessResponse(employeeVM, "Employee Suspended successfully", 200));
|
||||
}
|
||||
private static Employee GetNewEmployeeModel(CreateUserDto model, Guid TenantId, string ApplicationUserId)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user