public async Task <IActionResult> DeleteAsync(int id) { try { var label = await _labelRepository.GetLabelWithPhotosAsync(id); if (label == null) { return(NotFound($"Label with id '{id}' not found.")); } // Find all photos who use this label if (label.PhotoLabels != null && label.PhotoLabels.Count() != 0) { return(BadRequest($"Can not remove this label, cause it is in use.")); } await _labelRepository.DeleteLabelAsync(id); return(NoContent()); } catch (Exception) { var msg = "Error occurred while deleting data of database."; _logger.LogError(msg); return(StatusCode(StatusCodes.Status500InternalServerError, msg)); } }