public ActionResult Create(Note note) { if (ModelState.IsValid) { noteRepository.InsertOrUpdate(note); noteRepository.Save(); return RedirectToAction("Index"); } else { ViewBag.PossibleTasks = taskRepository.All; return View(); } }
public void InsertOrUpdate(Note note) { if (note.NoteId == default(int)) { // New entity note.CreatedOn = note.ModifiedOn = DateTime.UtcNow; context.Notes.Add(note); } else { // Existing entity note.ModifiedOn = DateTime.UtcNow; context.Entry(note).State = EntityState.Modified; } }