Added an API endpoint to delete a Work Category, allowing deletion only if IsSystem = false.
This commit is contained in:
parent
5953f37e57
commit
ec7e754f59
@ -639,5 +639,33 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
return BadRequest(ApiResponse<object>.ErrorResponse("User sent Empty payload", "User sent Empty payload", 400));
|
return BadRequest(ApiResponse<object>.ErrorResponse("User sent Empty payload", "User sent Empty payload", 400));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpDelete("work-category/{id}")]
|
||||||
|
public async Task<IActionResult> DeleteWorkCategoryMaster(Guid id)
|
||||||
|
{
|
||||||
|
var tenantId = _userHelper.GetTenantId();
|
||||||
|
var LoggedEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
|
WorkCategoryMaster? workCategory = await _context.WorkCategoryMasters.FirstOrDefaultAsync(t => t.TenantId == tenantId && t.Id == id);
|
||||||
|
if (workCategory != null)
|
||||||
|
{
|
||||||
|
if (workCategory.IsSystem == false)
|
||||||
|
{
|
||||||
|
_context.WorkCategoryMasters.Remove(workCategory);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInfo("Work category {WorkCategoryId} deleted successfully from tenant {tenantId}", id, tenantId);
|
||||||
|
return Ok(ApiResponse<object>.SuccessResponse(new { }, "Work category deleted successfully", 200));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Employee with {LoggedEmployeeId} tries to delete system-defined work category {WorkCategoryId}", LoggedEmployee.Id, id);
|
||||||
|
return BadRequest(ApiResponse<object>.ErrorResponse("Can not delete system-defined work category", "Can not delete system-defined work category", 400));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogError("Work category {WorkCategoryId} not found in database", id);
|
||||||
|
return NotFound(ApiResponse<object>.ErrorResponse("Work category not found", "Work category not found", 404));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user