Esempio n. 1
0
        public async Task <IActionResult> Edit(NoteEditModel model)
        {
            var note = _notesServices.GetNoteById(model.Id);

            note.Title       = model.Title;
            note.Description = model.Description;
            note.Content     = model.Content;

            await _notesServices.UpdateAsync(note);

            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        public ActionResult Edit(int id)
        {
            var detailModel = CreateNoteService().GetNoteById(id);
            var editModel   =
                new NoteEditModel
            {
                NoteId  = detailModel.NoteId,
                Title   = detailModel.Title,
                Content = detailModel.Content
            };

            return(View(editModel));
        }
Esempio n. 3
0
        public IActionResult Edit(int id)
        {
            var note = _notesServices.GetNoteById(id);

            var model = new NoteEditModel
            {
                Id          = note.Id,
                Title       = note.Title,
                Description = note.Description,
                Content     = note.Content
            };

            return(View(model));
        }
Esempio n. 4
0
        private bool SetStarState(int noteId, bool newState)
        {
            var userId  = Guid.Parse(User.Identity.GetUserId());
            var service = new NoteService(userId);

            var detail = service.GetNoteById(noteId);

            var updatedNote =
                new NoteEditModel
            {
                NoteId    = detail.NoteId,
                Title     = detail.Title,
                Content   = detail.Content,
                IsStarred = newState
            };

            return(service.UpdateNote(updatedNote));
        }
Esempio n. 5
0
        public ActionResult Save(NoteEditModel note)
        {
            var user = userRepositoty.LoadByLogin(User.Identity.Name);

            noteRepository.Save(new Note()
            {
                Id           = note.Id,
                Title        = note.Title,
                Published    = note.Published,
                Text         = note.Text,
                Tags         = GetTags(note.Tags),
                CreationDate = note.CreationDate,
                User         = user,
                File         = note.BinaryFile
            });

            return(RedirectToAction("Notes"));
        }
        public bool UpdateNote(NoteEditModel model)
        {
            using (var ctx = new ElevenNoteDbContext())
            {
                var entity = GetNoteFromDatabase(ctx, model.NoteId);

                if (entity == null)
                {
                    return(false);
                }

                entity.Title       = model.Title;
                entity.Content     = model.Content;
                entity.ModifiedUtc = DateTime.UtcNow;
                entity.IsStarred   = model.IsStarred;

                return(ctx.SaveChanges() == 1);
            }
        }
Esempio n. 7
0
        public IActionResult Edit(int id, NoteEditModel model)
        {
            if (!this.User.IsAuthenticated)
            {
                return(this.RedirectToHome());
            }

            if (!this.IsValidModel(model))
            {
                this.ShowError(CreateNoteErrorMessage);
                return(this.View());
            }

            this.noteService.Update(
                id,
                model.Title,
                model.Content);

            var user = this.userService.GetByName(this.User.Name);

            return(RedirectToAction($"/user/profile?id={user.Id}"));
        }
Esempio n. 8
0
        public ActionResult Edit(int id, NoteEditModel model)
        {
            if (model.NoteId != id)
            {
                ModelState.AddModelError("", "Nice try!");
                model.NoteId = id;
                return(View(model));
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (!CreateNoteService().UpdateNote(model))
            {
                ModelState.AddModelError("", "Unable to update note");
                return(View(model));
            }

            TempData["SaveResult"] = "Your note was saved";

            return(RedirectToAction("Index"));
        }