protected override async Task Handle(DeleteNetworkRequest request, CancellationToken cancellationToken) { var networkEntity = await _networkRepository.RetrieveNetworkAsync(request.Id); if (networkEntity == null) { throw new StatusException(StatusCodes.Status404NotFound, $"Network with id '{request.Id}' does not exist."); } if (networkEntity.Containers.Count > 0) { throw new StatusException(StatusCodes.Status403Forbidden, $"Network '{request.Id}' is still connected to '{networkEntity.Containers.Count}' container(s). Please disconnect them first."); } var success = await _networkRepository.DeleteNetworkAsync(request.Id); if (!success) { throw new StatusException(StatusCodes.Status500InternalServerError, $"Could not delete network with id '{request.Id}'."); } }