public ActionResult Create(Player player) { if (ModelState.IsValid) { playerRepository.InsertOrUpdate(player); playerRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }
public void InsertOrUpdate(Player player) { if (player.Id == default(int)) { // New entity context.Players.Add(player); } else { // Existing entity context.Players.Attach(player); context.Entry(player).State = EntityState.Modified; } }