Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
613 B
4
Indexable
Never
public async Task<IActionResult> DeleteTool(int id)
{
    try
    {
        var tool = await _context.Tools.FindAsync(id);
        if (tool == null)
        {
            return NotFound();
        }

        _context.Tools.Remove(tool);
        await _context.SaveChangesAsync();

        return NoContent(); // Return 204 No Content on successful deletion
    }
    catch (DbUpdateConcurrencyException ex)
    {
        // Log the error or handle it appropriately
        Console.WriteLine(ex.Message);
        return StatusCode(500, "An error occurred while deleting the tool.");
    }
}
Leave a Comment