public async Task <ActionResult <EntityModel> > Delete(int rasaNluId, int rasaNluDataId, int exampleId, int entityId, EntityModel model) { try { var entity = await _repository.GetEntityByExampleIdAsync(rasaNluId, rasaNluDataId, exampleId, entityId); if (entity == null) { return(NotFound($"Failed to find the Entity with Id: {entityId}")); } // Delete the Entity _repository.Delete(entity); if (await _repository.SaveChangesAsync()) { return(Ok()); } else { return(BadRequest($"Failed to Delte the Entity with Id: {exampleId}")); } } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } }
public async Task <IActionResult> Delete(int rasaNluId, int rasaNluDataId, int exampleId) { try { var commonExample = await _repository.GetExampleByRasaNluIdAsync(rasaNluId, rasaNluDataId, exampleId); if (commonExample == null) { return(NotFound($"Failed to find the example with Id: {exampleId}")); } var entities = await _repository.GetEntitiesByExampleIdAsync(rasaNluId, rasaNluDataId, exampleId); // Delete the CommonExample _repository.Delete(commonExample); if (entities != null) { foreach (var entity in entities) { // Delete all the entities that are related to commonExample _repository.Delete(entity); } } if (await _repository.SaveChangesAsync()) { return(Ok()); } else { return(BadRequest($"Failed to Delte the Common Example with Id: {exampleId}")); } } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } }