public ActionResult Edit(Guid id, EditStudentView editStudentView) { try { if (editStudentView.GetAge() <= 18) { ModelState.AddModelError(String.Empty, "User must be older or equal 18 years old"); } if (!ModelState.IsValid) { return(View(editStudentView)); } new StudentService().UpdateStudentById(id, Mapper.Map <Student>(editStudentView)); return(RedirectToAction("Index")); //StudentService studentService = new StudentService(); //Student student = studentService.GetStudentById(id); //EditStudentView selectedStudent = Mapper.Map<EditStudentView>(student); //return View(selectedStudent); } catch { return(View()); } }
public ActionResult Edit(Guid id, EditStudentView FormData) { try { if (FormData.GetAge() < 18) { ModelState.AddModelError("AgeInvalid", "Student age must be large than 18"); } if (!ModelState.IsValid) { return(View()); } StudentService studentService = new StudentService(); studentService.UpdateStudentById(id, FormData); return(RedirectToAction("Index")); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); return(View()); } }