public IActionResult Update(HeroEditViewModel heroVM) { if (!ModelState.IsValid) { heroVM.Powers = _powerRepository.GetAll(); return(View(heroVM)); } _repository.Update(heroVM.Hero); return(RedirectToAction("List")); }
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)); }
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)); }