public ActionResult Update(Stampante printer) { var validator = new StampantiValidator(); ValidationResult result = validator.Validate(printer); if (result.IsValid) { _stampantiRepository.UpdateStampante(printer); return(RedirectToAction("Index")); } else { foreach (ValidationFailure failer in result.Errors) { ModelState.AddModelError(failer.PropertyName, failer.ErrorMessage); } } return(View(printer)); }
public ActionResult Create(Stampante model) { var validator = new StampantiValidator(); ValidationResult result = validator.Validate(model); if (result.IsValid) { _stampantiRepository.AddStampante(model); string message = "Stampante aggiunta con successo"; ViewBag.Message = message; return(RedirectToAction("Index")); } else { foreach (ValidationFailure failer in result.Errors) { ModelState.AddModelError(failer.PropertyName, failer.ErrorMessage); } } return(View(model)); }