public async Task <IActionResult> Create(Color color) { if (ModelState.IsValid) { try { color.IsActive = true; color.CreationDate = DateTime.UtcNow; await _colorRepository.CreateAsync(color); return(RedirectToAction(nameof(Index))); } catch (Exception ex) { if (ex.InnerException.Message.Contains("duplicate")) { if (ModelState.IsValid) { ModelState.AddModelError(string.Empty, $"There is allready a color {color.ColorName} registered, please insert another"); return(View(color)); } } else { ModelState.AddModelError(string.Empty, ex.InnerException.Message); return(View(color)); } } } return(View(color)); }