public ActionResult Edit() { TeamsService teamsService = new TeamsService(); TeamsEditVM model = new TeamsEditVM(); TryUpdateModel(model); if (!ModelState.IsValid) { return View(model); } Team team; if (model.ID == 0) { team = new Team(); } else { team = teamsService.GetByID(model.ID); if (team == null) { return RedirectToAction("List"); } } team.ID = model.ID; team.Name = model.Name; teamsService.Save(team); return RedirectToAction("List"); }
public ActionResult Edit(int? id) { TeamsService teamsService = new TeamsService(); TeamsEditVM model = new TeamsEditVM(); Team team; if (!id.HasValue) { team = new Team(); } else { team = teamsService.GetByID(id.Value); if (team == null) { return RedirectToAction("List"); } } model.ID = team.ID; model.Name = team.Name; return View(model); }