Example #1
0
        public ActionResult Delete(int id)
        {
            var uow = UnitOfWorkProvider.GetCurrent();
            var notesRepository = new IntKeyedRepository<Note>(uow.Session);

            notesRepository.Remove(id);

            return RedirectToAction("Index");
        }
Example #2
0
        //
        // GET: /Notes/
        public ActionResult Index()
        {
            var uow = UnitOfWorkProvider.GetCurrent();
            var notesRepository = new IntKeyedRepository<Note>(uow.Session);

            var notes = notesRepository.GetAll();

            var notesViewModel = notes.Select(x => new NoteViewModel()
                                  {
                                      Id = x.Id,
                                      Text = x.Text
                                  }).ToList();

            return View(notesViewModel);
        }
Example #3
0
        public ActionResult Edit(int id)
        {
            var uow = UnitOfWorkProvider.GetCurrent();
            var notesRepository = new IntKeyedRepository<Note>(uow.Session);

            var note = notesRepository.Get(id);

            var noteViewModel = new NoteViewModel()
                                    {
                                        Id = note.Id,
                                        Text = note.Text
                                    };

            return View(noteViewModel);
        }
Example #4
0
        public ActionResult Create(NoteViewModel noteViewModel)
        {
            var uow = UnitOfWorkProvider.GetCurrent();

            if (ModelState.IsValid)
            {
                var note = new Note()
                {
                    Text = noteViewModel.Text
                };

                var notesRepository = new IntKeyedRepository<Note>(uow.Session);
                notesRepository.Add(note);

                return RedirectToAction("Index");
            }

            return RedirectToAction("New");
        }