Add the Delete Endpoint
Add the Service Method
In the TaskService.cs file add the following method
public async Task DeleteTaskAsync(int id)
{
using var conn = await _connectionFactory.CreateConnectionAsync();
var parameters = new DynamicParameters();
parameters.Add("@Id", id);
await conn.ExecuteAsync("DeleteTask", parameters, commandType: CommandType.StoredProcedure);
}
Add the Endpoint
In the TaskEndpoints.cs file add the following endpoint
app.MapDelete("/api/tasks/{id:int}", async (int id, TaskService service) =>
{
await service.DeleteTaskAsync(id);
return Results.Ok();
});
Test the Endpoint
In Postman or Rider etc
DELETE /api/tasks/2
12 July 2025