public ActionResult Create(VMEngine model)
        {
            var validator = new EngineValidator();
            var result    = validator.Validate(model.Eng);

            if (result.Errors.Any())
            {
                foreach (var item in result.Errors)
                {
                    ModelState.AddModelError("", item.ErrorMessage);
                }
            }
            else
            {
                _engineRepository.Create(model.Eng);
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
示例#2
0
        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));
        }