Beispiel #1
0
 public void UpdateNote(UpdateNoteViewModel model)
 {
     if (ModelState.IsValid)
     {
         SqlCommand command = new SqlCommand(
             "UPDATE Note " +
             "SET Title = @title, Content = @content " +
             "WHERE ID= @id");
         SqlParameter NID = new SqlParameter
         {
             ParameterName = "@id",
             Value         = model.ID.GetDirectReference()
         };
         SqlParameter TTL = new SqlParameter
         {
             ParameterName = "@title",
             Value         = model.Title
         };
         SqlParameter CTT = new SqlParameter
         {
             ParameterName = "@content",
             Value         = model.Content
         };
         command.Parameters.Add(NID);
         command.Parameters.Add(TTL);
         command.Parameters.Add(CTT);
         Debug.WriteLine(model.ID.GetDirectReference() + model.Title + model.Content);
         Utility.Constants.CallDB(command);
     }
 }
Beispiel #2
0
        public IHttpActionResult UpdateNote([FromBody] UpdateNoteViewModel viewModel)
        {
            var note = this.noteRepository.GetByKey(viewModel.ID);

            if (note != null)
            {
                note = Mapper.Map(viewModel, note);
            }
            this.noteRepository.Update(note);
            this.RepositoryContext.Commit();
            return(this.Ok());
        }
        public void UpdateNoteTest()
        {
            var updateViewModel = new UpdateNoteViewModel
            {
                Content = "updated",
                ID      = guid2,
                Title   = "updated title",
                Weather = "Foggy"
            };

            var notesController = new NotesController(MockRepositoryContext.Object, mockNoteRepository.Object);

            notesController.UpdateNote(updateViewModel);

            Assert.AreEqual(updateViewModel.Content, notes[1].Content);
            Assert.AreEqual(guid2, notes[1].ID);
            Assert.AreEqual(updateViewModel.Title, notes[1].Title);
            Assert.AreEqual(Weather.Foggy, notes[1].Weather);
        }
Beispiel #4
0
        public IActionResult Update(string id, [FromForm] UpdateNoteViewModel model)
        {
            if (!_noteService.CheckIfExists(id))
            {
                return(View(Views.NotFound, id));
            }

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

            var noteToUpdate = _mapper.Map <Note>(model);

            _noteService.Update(noteToUpdate);

            var idModel = new
            {
                id = model.Id
            };

            return(RedirectToAction(NoteActions.GetNote, ControllerNames.Note, idModel));
        }
Beispiel #5
0
 public IActionResult Update(UpdateNoteViewModel note)
 {
     _noteService.Update(note);
     return(Ok());
 }
Beispiel #6
0
        public void Update(UpdateNoteViewModel noteModel)
        {
            var note = _mapper.Map <Note>(noteModel);

            _noteRepository.Update(note);
        }
        public void UpdateNoteTest()
        {
            var updateViewModel = new UpdateNoteViewModel
                                      {
                                          Content = "updated",
                                          ID = guid2,
                                          Title = "updated title",
                                          Weather = "Foggy"
                                      };

            var notesController = new NotesController(MockRepositoryContext.Object, mockNoteRepository.Object);
            notesController.UpdateNote(updateViewModel);

            Assert.AreEqual(updateViewModel.Content, notes[1].Content);
            Assert.AreEqual(guid2, notes[1].ID);
            Assert.AreEqual(updateViewModel.Title, notes[1].Title);
            Assert.AreEqual(Weather.Foggy, notes[1].Weather);
        }