private List <ChapterDataModel> LoadChapters() { using (BookDataContext context = BookDataContext.Connect()) { var chaptersInBook = from chapter in context.Chapters where chapter.BookID == BookId orderby chapter.TokenID select chapter; var source = new List <ChapterDataModel>(); foreach (ChapterModel chapterModel in chaptersInBook) { int tokenID = chapterModel.TokenID; var chapter = new ChapterDataModel { Depth = chapterModel.Level, Title = chapterModel.Title.Trim(), TokenId = tokenID }; source.Add(chapter); } return(source); } }
public static ChapterDataModel GetChapterModelForEdit(Document opus, int?chapterId, Action <Element> saveNewChapter) { // we read chapter by chapter, which is the first level in the hierarchy by definition var chapters = opus.Children.OfType <Section>().OrderBy(c => c.OrderNr).ToList(); Element currentChapter = null; Element prevChapter = null; Element nextChapter = null; IEnumerable <SnippetDataModel> run = null; if (chapterId.HasValue && chapters.Any()) { currentChapter = chapters.SingleOrDefault(c => c.Id == chapterId); if (currentChapter == null) // If chapter was deleted. { currentChapter = chapters.Last(); } } if (!chapterId.HasValue && chapters.Any()) { currentChapter = chapters.First(); } if (currentChapter != null) { // take tha chapters content for view run = FlattenHierarchy(currentChapter); // take prev and next from index var idx = chapters.FindIndex(c => c.Id == currentChapter.Id); prevChapter = chapters.ElementAtOrDefault(idx - 1); nextChapter = chapters.ElementAtOrDefault(idx + 1); } else { // Create the first chapter on the fly and add to the DB immediately currentChapter = new Section { Parent = opus, Name = "Chapter 1", OrderNr = 1, Content = System.Text.Encoding.UTF8.GetBytes("Chapter 1") }; saveNewChapter(currentChapter); run = new List <SnippetDataModel>(new[] { new SnippetDataModel { CurrentSnippet = currentChapter, ChapterId = currentChapter.Id, SnippetTitle = currentChapter.Name, CanDown = false, CanUp = false } }); } var rm = new ChapterDataModel { DocumentId = opus.Id, GenericChapterNumber = currentChapter.OrderNr, CurrentChapter = currentChapter, ChapterElements = run, ChapterTitle = currentChapter.RawContent.Ellipsis(40).ToHtmlString(), PreviousChapter = prevChapter, PreviousChapterTitle = (prevChapter == null) ? "" : prevChapter.Name, NextChapter = nextChapter, NextChapterTitle = (nextChapter == null) ? "" : nextChapter.Name, }; return(rm); }
public void GoToChapter(ChapterDataModel chapter) { _navigationService.UriFor <ReadPageViewModel>() .WithParam(vm => vm.BookId, BookId) .WithParam(vm => vm.TokenOffset, chapter.TokenId) .WithParam(vm => vm.CatalogId, CatalogId) .WithParam(vm => vm.CatalogBookItemKey, TransientStorage.Put(CatalogBookItemModel)) .Navigate(); }