public ChapterDetail GetChapter(ChapterCriteria criteria) { using (var uow = UnitOfWorkFactory.Create <NovelContext>()) { var service = new ChapterService(uow); var detail = service.Get(criteria); // novel detail.Novel = service.View <Novel>().Where(w => w.ID == detail.NovelID).Single(); // chapter content var contents = service.View <Content>().Where(w => w.ChapterID == detail.ID).Select(s => new ContentGrid { ID = s.ID, RawHash = s.RawHash, Final = s.Final, }).ToList(); // summarize detail.Summarize = service.View <Summarize>().Where(w => w.SourceTable == R.SourceTable.CHAPTER && w.SourceID == detail.ID).SingleOrDefault() ?? new Summarize(); // glossary detail.Glossaries = service.View <Glossary>().Where(w => w.SourceTable == R.SourceTable.NOVEL && w.SourceID == detail.NovelID).ToList(); // checked var contentIDs = contents.Select(s => s.ID).ToList(); detail.Checks = service.View <Check>().Where(w => w.IsDeleted == false && contentIDs.Contains(w.SourceID) && w.SourceTable == R.SourceTable.CONTENT).ToList(); // segments (paragraphs) var paragraphs = detail.Content.ToParagraphs().Select((s, i) => new { Index = i, Raw = s, RawHash = s.GetIntHash() }); detail.Contents = paragraphs.Join(contents, p => p.RawHash, c => c.RawHash, (p, c) => new ContentGrid { ID = c.ID, Final = c.Final, Paragraph = p.Index, RawHash = p.RawHash, Raw = p.Raw, IsTranslated = detail.Checks.Any(w => w.Type == R.CheckType.TRANSLATING && w.SourceID == c.ID), IsEdited = detail.Checks.Any(w => w.Type == R.CheckType.EDITING && w.SourceID == c.ID), IsProofread = detail.Checks.Any(w => w.Type == R.CheckType.PROOFREADING && w.SourceID == c.ID), }).ToList(); return(detail); } }