public ActionResult Create(VMEngines model) { var validator = new EngineValidator(); var result = validator.Validate(model.Engine); if (result.Errors.Any()) { foreach (var item in result.Errors) { ModelState.AddModelError("", item.ErrorMessage); } } else { _enginesRepository.Create(model.Engine); return(RedirectToAction("Index")); } return(View(model)); }
public ActionResult Create(VMEngine model) { //w kontrolerze dodajemy walidację - wywołujemy, żeby zadziałało, usuwamy isValid, bo to odnosi do dataannotation //to samo robimy dla edit var validator = new EngineValidator(); var result = validator.Validate(model.Engine); if (result.Errors.Any()) { foreach (var item in result.Errors) { ModelState.AddModelError("", item.ErrorMessage); } } else { _engineRepository.Create(model.Engine); return(RedirectToAction("Index")); } return(View(model)); }