public async Task <IActionResult> Delete(string id) { //if (id == null) return BadRequest(); //not needed as middleware only calls this action if id is present; otherwise, it will try a different route, e.g. causing 405 (Method Not Allowed) if PUT request w/o id. if (_saleService.ContainsParentId(id)) { return(BadRequest(this.BadRequestDetails("Integrity validation failed.", $"At least one Sale is associated with Broker '{id}'."))); } //Note that to enforce validaed integrity above, this Delete action needs to constitute unit of work (currently not the case as uow is controlled by StorageController) //TODO: add the above validation to brokere delete service below (i.e. remove dependency on sale service - see ctor); requires expansion to ServiceResult to discriminate between 400 & 404 responses (uow refactoring will still be needed to enforce data integrity). var svcRslt = await _brokerService.DeleteAsync(id); if (!svcRslt.Success) { return(NotFound()); } return(NoContent()); }