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