public void InsertOrUpdate(Cycle cycle) { if (cycle.Id == default(int)) { // New entity context.Cycles.Add(cycle); } else { // Existing entity context.Entry(cycle).State = EntityState.Modified; } }
public ActionResult Create(Cycle cycle) { if (ModelState.IsValid) { cycleRepository.InsertOrUpdate(cycle); cycleRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }