public ActionResult Create(Rank rank) { if (ModelState.IsValid) { rankRepository.InsertOrUpdate(rank); rankRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }
public void InsertOrUpdate(Rank rank) { if (rank.ID == default(int)) { // New entity context.Rank.Add(rank); } else { // Existing entity context.Rank.Attach(rank); context.Entry(rank).State = EntityState.Modified; } }