public IHttpActionResult Delete(int id) { if (!ModelState.IsValid) { return(this.Error().InvalidParameters("Invalid pass parameters")); } // Check that pass exists Pass pass = _passRepository.Get(id); if (pass == null) { return(NotFound()); } // Get scenarios that reference pass var scenarios = _scenarioRepository.GetByPassId(id); if (scenarios.Any()) { return(this.Error().BadRequest("Cannot delete a pass because a scenario has a dependency on it")); } _passRepository.Delete(id); _passRepository.SaveChanges(); return(this.NoContent()); }