public async Task <IActionResult> Delete(int?id) { if (id == null) { return(NotFound()); } try { await _specialityRepository.DeleteSpecialityAsync(id.Value); } //catch (DbUpdateException dbUpdateException) //{ // if (dbUpdateException.InnerException.Message.Contains("delete")) // { // ModelState.AddModelError(string.Empty, "This record have doctors."); // } // else // { // ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); // } //} catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } return(RedirectToAction(nameof(Index))); }