コード例 #1
0
        public ActionResult New(int personId)
        {
            ViewBag.Title = "New Degree";
            var viewModel = new EducationFormViewModel(personId);

            return(View("EducationForm", viewModel));
        }
コード例 #2
0
        public ActionResult Save(Education education)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new EducationFormViewModel(education);
                return(View("EducationForm", viewModel));
            }

            if (education.Id == 0)
            {
                _context.Educations.Add(education);
            }
            else
            {
                var educationInDb = _context.Educations.Single(e => e.Id == education.Id);

                educationInDb.Degree     = education.Degree;
                educationInDb.University = education.University;
            }


            _context.SaveChanges();

            return(RedirectToAction("Index", "Education", new { id = education.PersonId }));
        }
コード例 #3
0
        public ActionResult Edit(int id)
        {
            var education = _context.Educations.SingleOrDefault(e => e.Id == id);

            if (education == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new EducationFormViewModel(education);

            ViewBag.Title = "Edit Degree";
            return(View("EducationForm", viewModel));
        }