public ActionResult Create(NotesCreateVM model) { if (ModelState.IsValid) { Note note = new Note { ID = model.Id, ContactId = model.ContactId, Text = model.Text }; if (model.Id <= 0) { note.DateCreated = DateTime.Now; note.DateLastEdit = DateTime.Now; unitOfWork.NoteRepository.Insert(note); } else { note.DateLastEdit = DateTime.Now; note.DateCreated = model.DateCreated; unitOfWork.NoteRepository.Update(note); } unitOfWork.Save(); return(RedirectToAction("Index/" + note.ContactId)); } return(View(model)); }
public ActionResult Delete(NotesCreateVM model) { unitOfWork.NoteRepository.Delete(model.Id); unitOfWork.Save(); return(RedirectToAction("Index/" + model.ContactId)); }
public ActionResult Create(int?contactId) { if (!contactId.HasValue) { return(RedirectToAction("Index")); } NotesCreateVM model = new NotesCreateVM(); model.ContactId = contactId.Value; return(View(model)); }
public ActionResult Edit(int?contactId, int?id) { if (!id.HasValue || !contactId.HasValue) { return(RedirectToAction("Index")); } Note note = unitOfWork.NoteRepository.GetById(id.Value); if (note == null) { return(Redirect("~/Error/PageNotFound")); } NotesCreateVM model = new NotesCreateVM(); model.Id = note.ID; model.Text = note.Text; model.DateCreated = note.DateCreated; model.DateLastEdit = note.DateLastEdit; model.ContactId = contactId.Value; return(View("Create", model)); }