The Delete action method is marked with the HttpDelete attribute. It usually accepts the identifier of the resource to remove.
In our case, we are going to implement a real delete operation on our IOrderRepository. The Delete action methods usually return a 204 No Content error to confirm the deletion or a 404 Not Found error if the client passes a non-existent identifier:
[HttpDelete("{id:guid}")]
public IActionResult Delete(Guid id)
{
var order = _orderRepository.Get(id);
if (order == null)
{
return NotFound(new { Message = $"Item with id {id} not exist." });
}
_orderRepository.Delete(id);
return NoContent();
}
The implementation fetches the resource with the corresponding id from the IOrderRepository interface. It proceeds by checking whether the resource is null, and in this case, it will produce a not found error. If the order entity is present in the data source, it continues with the deletion process, and it returns a no content result. Now, let's proceed by having a look at the asynchronous process using a web service.