コード例 #1
0
        public ActionResult Save(Profession profession)
        {
            if (!ModelState.IsValid)
            {
                var categories = _context.Categories.ToList();
                var viewModel  = new ProfessionFormViewModel
                {
                    Categories = categories
                };


                return(View("ProfessionForm", viewModel));
            }


            if (profession.Id == 0)
            {
                _context.Professions.Add(profession);
            }
            else
            {
                var professionInDb = _context.Professions.Single(p => p.Id == profession.Id);

                professionInDb.Name          = profession.Name;
                professionInDb.Category      = profession.Category;
                professionInDb.Description   = profession.Description;
                professionInDb.CategoryId    = profession.CategoryId;
                professionInDb.Professionals = profession.Professionals;
            }

            _context.SaveChanges();


            return(RedirectToAction("Index", "Professions"));
        }
コード例 #2
0
        public ActionResult New()
        {
            var categories = _context.Categories.ToList();
            var viewModel  = new ProfessionFormViewModel
            {
                Categories = categories
            };


            return(View("ProfessionForm", viewModel));
        }
コード例 #3
0
        public ActionResult Edit(int id)
        {
            var profession = _context.Professions.SingleOrDefault(p => p.Id == id);

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

            var viewModel = new ProfessionFormViewModel
            {
                Profession = profession,
                Categories = _context.Categories.ToList()
            };

            return(View("ProfessionForm", viewModel));
        }