示例#1
0
 public ActionResult Create(Player player)
 {
     if (ModelState.IsValid) {
         playerRepository.InsertOrUpdate(player);
         playerRepository.Save();
         return RedirectToAction("Index");
     } else {
         return View();
     }
 }
示例#2
0
 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;
     }
 }