public ActionResult Save(Move move) { if (!ModelState.IsValid) { var viewModel = new MoveFormViewModel() { Move = move }; return(View("MoveForm", viewModel)); } var moveInDb = _context.Moves.SingleOrDefault(c => c.Id == move.Id) ?? _context.Moves.Add(move); var moveInDbName = _context.Moves.FirstOrDefault(c => c.Name == move.Name); if (moveInDbName != null && moveInDbName.CharacterId != move.CharacterId) { return(RedirectToAction("New")); } moveInDb.Name = move.Name; moveInDb.Input = move.Input; moveInDb.ActiveFrames = move.ActiveFrames; moveInDb.StartupFrames = move.StartupFrames; moveInDb.RecoveryFrames = move.RecoveryFrames; moveInDb.FrameAdvantage = move.FrameAdvantage; _context.SaveChanges(); return(RedirectToAction("Index", "MovesAdmin")); }
public ActionResult New() { var character = _context.Characters.ToList(); var viewModel = new MoveFormViewModel() { Move = new Move(), Character = character }; return(View("MoveForm", viewModel)); }
public ActionResult Edit(int id) { var move = _context.Moves.SingleOrDefault(c => c.Id == id); if (move == null) { return(HttpNotFound()); } var viewModel = new MoveFormViewModel() { Move = move, Character = _context.Characters.ToList() }; return(View("MoveForm", viewModel)); }