private void InsertNote(BibleNote note) { var book = note.BookChapterAndVerse.BookNumber; var chapter = note.BookChapterAndVerse.ChapterNumber; var location = _targetDatabase.FindLocationByBibleChapter(_bibleKeySymbol, book, chapter) ?? InsertLocation(book, chapter); UserMark?userMark = null; if (note.StartTokenInVerse != null && note.EndTokenInVerse != null) { // the note should be associated with some // highlighted text in the verse. userMark = FindExistingUserMark( location.LocationId, note.StartTokenInVerse.Value, note.EndTokenInVerse.Value) ?? InsertUserMark( location.LocationId, note.ColourIndex, note.StartTokenInVerse.Value, note.EndTokenInVerse.Value, note.BookChapterAndVerse.VerseNumber); } var newNote = new Note { NoteId = ++_maxNoteId, Guid = Guid.NewGuid().ToString().ToLower(), UserMarkId = userMark?.UserMarkId, LocationId = location.LocationId, Title = note.NoteTitle, Content = note.NoteContent, BlockType = 2, BlockIdentifier = note.BookChapterAndVerse.VerseNumber, LastModified = Database.GetDateTimeUtcAsDbString(DateTime.UtcNow), }; var newTagMapEntry = _options.TagId == 0 ? null : CreateTagMapEntryForImportedBibleNote(newNote.NoteId, _options.TagId, _tagMapPositionToUse++); _targetDatabase.AddBibleNoteAndUpdateIndex( note.BookChapterAndVerse, newNote, newTagMapEntry); }
private Note FindExistingNote(Database database, BibleNote note) { var existingVerseNotes = database.FindNotes(note.BookChapterAndVerse); return(existingVerseNotes?.FirstOrDefault(verseNote => verseNote.Title == note.NoteTitle)); }