public IActionResult Create(Country item) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { return(Ok(_countryRepository.Create(item))); } catch { return(BadRequest(ModelState)); //or can throw new Exception } }
public ActionResult Create(Country country) { try { if (ModelState.IsValid) { countryRepository.Create(country); return(RedirectToAction("Index")); } return(View(country)); } catch { // return RedirectToAction("Create"); return(View()); } }