public ActionResult Create(CourseViewModel courseViewModel) { ViewBag.Title = "Novo registro"; ViewBag.CourseTypeId = new SelectList(courseTypeAppService.GetActive(), "Id", "Identification"); ViewBag.InstructorId = new SelectList(instructorAppService.GetActive(), "Id", "Identification"); if (ModelState.IsValid) { courseViewModel = courseAppService.Add(courseViewModel); if (!courseViewModel.ValidationResult.IsValid) { foreach (var error in courseViewModel.ValidationResult.Erros) { ModelState.AddModelError(string.Empty, error.Message); } return(View(courseViewModel)); } return(RedirectToAction("Index")); } return(View(courseViewModel)); }
public ActionResult Create(CourseViewModel course) { if (ModelState.IsValid) { var courseDomain = Mapper.Map <CourseViewModel, Course>(course); _courseApp.Add(courseDomain); return(RedirectToAction("Index")); } return(View(course)); }