public async Task <IActionResult> UpdateNote(int id, NoteForUpdateDto noteForUpdateDto) { var noteFromRepo = await _repository.GetNote(id); try { _mapper.Map(noteForUpdateDto, noteFromRepo); await _repository.SaveAll(); return(NoContent()); } catch (Exception) { return(NoContent()); } }
public ActionResult UpdateBookNote(Guid bookId, Guid noteId, NoteForUpdateDto note) { if (!_bookRepository.BookExists(bookId)) { return(NotFound()); } var bookNoteFromRepo = _noteRepository.GetNote(bookId, noteId); if (bookNoteFromRepo == null) { return(NotFound()); } // map the entity to a NoteForUpdateDto // apply the updated field values to that dto // map the NoteForUpdateDto back to an entity _mapper.Map(note, bookNoteFromRepo); _noteRepository.UpdateNote(bookNoteFromRepo); _noteRepository.Save(); return(NoContent()); }