Пример #1
0
        private Course GetCourse()
        {
            RockContext rockContext = new RockContext();

            var courseId = PageParameter(PageParameterKeys.CourseId).AsIntegerOrNull();

            if (courseId != null)
            {
                CourseService courseService = new CourseService(rockContext);
                return(courseService.Get(courseId.Value));
            }

            var chapterId = PageParameter(PageParameterKeys.ChapterId).AsIntegerOrNull();

            if (chapterId != null)
            {
                ChapterService chapterService = new ChapterService(rockContext);
                var            chapter        = chapterService.Get(chapterId.Value);
                return(chapter.Course);
            }

            var coursePageId = PageParameter(PageParameterKeys.CoursePageId).AsIntegerOrNull();

            if (coursePageId != null)
            {
                CoursePageService coursePageService = new CoursePageService(rockContext);
                return(coursePageService.Get(coursePageId.Value).Chapter.Course);
            }

            return(null);
        }
Пример #2
0
        private Chapter GetChapter(ChapterService chapterService)
        {
            var coursepageId = PageParameter(PageParameterKey.CoursePageId).AsIntegerOrNull();

            if (coursepageId.HasValue)
            {
                return(null);
            }

            var chapterId = PageParameter(PageParameterKey.ChapterId).AsIntegerOrNull();

            if (!chapterId.HasValue)
            {
                return(null);
            }

            var chapter = chapterService.Get(chapterId.Value);

            if (chapter == null)
            {
                chapter = new Chapter()
                {
                    CourseId = PageParameter(PageParameterKey.CourseId).AsInteger()
                };
            }

            return(chapter);
        }
Пример #3
0
        protected void btnDelete_Click(object sender, RowEventArgs e)
        {
            var            id             = ( int )e.RowKeyValue;
            RockContext    rockContext    = new RockContext();
            ChapterService chapterService = new ChapterService(rockContext);
            var            coursePage     = chapterService.Get(id);

            if (coursePage != null)
            {
                chapterService.Delete(coursePage);
                rockContext.SaveChanges();
            }

            BindGrid();
        }
Пример #4
0
        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);
            }
        }