コード例 #1
0
        public IActionResult Update(HeroEditViewModel heroVM)
        {
            if (!ModelState.IsValid)
            {
                heroVM.Powers = _powerRepository.GetAll();
                return(View(heroVM));
            }
            _repository.Update(heroVM.Hero);

            return(RedirectToAction("List"));
        }
コード例 #2
0
        public IActionResult Update(int id)
        {
            Hero hero = _repository.FindWithPower(a => a.PowerId == id).FirstOrDefault();

            if (hero == null)
            {
                return(NotFound());
            }

            var heroVM = new HeroEditViewModel
            {
                Hero   = hero,
                Powers = _powerRepository.GetAll()
            };

            return(View(heroVM));
        }
コード例 #3
0
        public IActionResult Create(int?powerId)
        {
            Hero hero = new Hero();

            if (powerId != null)
            {
                hero.PowerId = (int)powerId;
            }

            var heroVM = new HeroEditViewModel
            {
                Powers = _powerRepository.GetAll(),
                Hero   = hero
            };

            return(View(heroVM));
        }