示例#1
0
        public ActionResult CreateNote()
        {
            ViewBag.TopicId = new SelectList(_repositoryTopic.GetAll(), "Id", "Name");

            //Альтернативный вариант для выпадающего списка с Importance
            //var values = from Importance e in Enum.GetValues(typeof(Importance))
            //             select new { Id = (int)e, Name = e.ToString() };
            //ViewBag.Importance = new SelectList(values.ToList(), "Id", "Name");

            NoteWithTextViewModel note = new NoteWithTextViewModel
            {
                Date = DateTime.Now
            };

            return(View(note));
        }
示例#2
0
        public ActionResult DetailsNote(int id)
        {
            Note note = _repositoryNote.Details(id);

            //TODO: сопоставление надо через Automapper
            NoteWithTextViewModel noteViewModel = new NoteWithTextViewModel
            {
                Id         = note.Id,
                Date       = note.Date,
                Header     = note.Header,
                TopicId    = note.TopicId,
                Importance = note.Importance,
                Text       = note.Text.Entry
            };

            return(View(noteViewModel));
        }
示例#3
0
        public ActionResult CreateNote(NoteWithTextViewModel noteWithText)
        {
            //TODO: переделать с использованием AutoMapper
            Note note = new Note
            {
                Date       = noteWithText.Date,
                Header     = noteWithText.Header,
                TopicId    = noteWithText.TopicId,
                Importance = noteWithText.Importance,
                Text       = new Text {
                    Entry = noteWithText.Text
                }
            };

            _repositoryNote.Add(note);

            return(RedirectToAction("Index"));
        }