public ActionResult Create(Team team) { if (ModelState.IsValid) { teamRepository.InsertOrUpdate(team); teamRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }
public void InsertOrUpdate(Team team) { if (team.TeamId == default(int)) { // New entity context.Teams.Add(team); } else { // Existing entity context.Teams.Attach(team); context.Entry(team).State = EntityState.Modified; } }