Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        public ActionResult Delete(NotesCreateVM model)
        {
            unitOfWork.NoteRepository.Delete(model.Id);
            unitOfWork.Save();

            return(RedirectToAction("Index/" + model.ContactId));
        }
Esempio n. 3
0
        public ActionResult Create(int?contactId)
        {
            if (!contactId.HasValue)
            {
                return(RedirectToAction("Index"));
            }

            NotesCreateVM model = new NotesCreateVM();

            model.ContactId = contactId.Value;
            return(View(model));
        }
Esempio n. 4
0
        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));
        }