public IActionResult Delete(int Id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { return(Ok(_familyRepository.Delete(Id))); //or you can throw new Exception } catch { return(BadRequest(ModelState)); } }