public async Task <IActionResult> Create(PetType petType) { if (ModelState.IsValid) { try { await _petTypeRepository.CreatePetTypeAsync(petType); return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, "There are a record with the same name."); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } return(View(petType)); }