public void CreateNote(NoteViewModel noteViewModel) { Note note = noteViewModel.ToNote(); Writer writer = _writerRepository.GetById(note.WriterId); if (writer == null) { //log exception throw new Exception($"Writer with id {note.WriterId} was not found!"); } note.Writer = writer; int newNoteId = _noteRepository.Insert(note); if (newNoteId <= 0) { throw new Exception("Something went wrong while saving the note"); } }
public void EditNote(NoteViewModel noteViewModel) { Note noteDb = _noteRepository.GetById(noteViewModel.Id); if (noteDb == null) { //log throw new Exception($"The note with id {noteViewModel.Id} was not found!"); } Writer writerDb = _writerRepository.GetById(noteViewModel.WriterId); if (writerDb == null) { //log throw new Exception($"The writer with id {noteViewModel.WriterId} was not found!"); } Note editedNote = noteViewModel.ToNote(); editedNote.Writer = writerDb; _noteRepository.Update(editedNote); }