public ActionResult Create(Task task) { if (ModelState.IsValid) { taskRepository.InsertOrUpdate(task); taskRepository.Save(); return RedirectToAction("Index"); } else { return View(); } }
public void InsertOrUpdate(Task task) { if (task.TaskId == default(System.Guid)) { // New entity task.TaskId = Guid.NewGuid(); context.Task.Add(task); } else { // Existing entity context.Entry(task).State = EntityState.Modified; } }