/// <summary> /// 保存章节 /// </summary> /// <returns></returns> public bool Save() { ThrowExceptionIfValidateFailure(); Data.Entity.Chapter chapter = new Data.Entity.Chapter { ChapterId = ID, Content = Content, Count = Count, CourseId = CourseId, CreateTime = DateTime.Now, ParentId = ParentId, ParentPath = ChapterTools.CreateParentPath(ParentChapter, ID), Status = Status, Title = Title, Video = Video, IsLeaf = true }; bool success = ChapterAccessor.Insert(chapter); if (success) { ComputeStudyProgress(CourseId); } return(success); }
/// <summary> /// 如果检测到该课程已学习完成,将更新用户课程完成数量 /// </summary> public override void Execute() { Validate(); var state = State as CourseStudyFinishedCheckEventState; //获取课程下的所有章节状态信息 var courseChapters = ChapterAccessor.GetChaptersAllFor(state.CoureseId); //有效的课程章节 var enableChapters = courseChapters.Where(p => p.Status == (int)ChapterStatus.ENABLED); //有效的课程章节ID集合 var enabledChapterIds = enableChapters.Select(p => p.ChapterId); //有效的课程章节数 var enabledCount = enableChapters != null?enableChapters.Count() : 0; //获取用户当前课程学习过的章节信息 var studiedChapters = StudyRecordAccessor.GetChapterIdsFor(state.StudentId, state.CoureseId); //已学习过的课程章节数 var studiedCount = studiedChapters.Count(p => enabledChapterIds.Contains(p)); //如果:课程中开启的章节数均已学习完成,则更新用户课程完成数 if (enabledCount == studiedCount) { UserStudyAccessor.UpdateReadedCourse(state.StudentId, 1); } }
/// <summary> /// 实例化<see cref="StudingRecord"/>对象实例 /// </summary> /// <param name="studentId">学员ID</param> /// <param name="chapterId">学习的课程章节ID</param> public StudingRecord(long studentId, long chapterId) { StudentId = studentId; //获取章节信息 Chapter = ChapterAccessor.Get(chapterId); InitData(); }
/// <summary> /// 获取父章节标题 /// </summary> /// <returns></returns> public string GetParentChapterTitle() { if (Chapter.ParentId > 0) { return(ChapterAccessor.GetTitle(Chapter.ParentId)); } return(string.Empty); }
/// <summary> /// 执行搜索 /// </summary> public PagerModel <Data.Entity.Chapter> Search() { this.ThrowExceptionIfValidateFailure(); PagerModel <Data.Entity.Chapter> pager = new PagerModel <Data.Entity.Chapter>() { Index = PageIndex, Size = PageSize }; ChapterAccessor.Get(pager, Keyword, courseId: CourseId, status: Status); return(pager); }
public override void Execute() { var state = State as StudyRecordTimesUpdateEventState; Validate(); //获取章节的所有父级章节ID var chapterIds = ChapterAccessor.GetParentsIds(state.ChapterId); if (state.IncludeMySelf) { chapterIds.Add(state.ChapterId); } StudyRecordAccessor.AddOnceTimesForStudy(state.StudentId, chapterIds); }
public bool Remove() { ThrowExceptionIfValidateFailure(() => { if (!CanDelete()) { AddBrokenRule(ChapterManageFailureRule.CANNOT_DELETE); } }); bool success = ChapterAccessor.Remove(ID); if (success) { ComputeStudyProgress(Chapter.CourseId); } return(success); }
public bool SetDisable() { ThrowExceptionIfValidateFailure(() => { if (!CanSetDisable()) { AddBrokenRule(ChapterManageFailureRule.STATUS_CANNOT_SET_TO_DISABLE); } }); bool success = ChapterAccessor.SetStatus(ID, (int)ChapterStatus.DISABLED); if (success) { ComputeStudyProgress(Chapter.CourseId); } return(success); }
/// <summary> /// 计算课程的学习进度 /// </summary> /// <returns></returns> public float Calculate() { //获取用户学习过的章节数 long[] studied = StudyRecordAccessor.GetChapterIdsFor(UserId, CourseId); //当前课程未学习过任何章节,学习进度为0 if (studied == null || studied.Length == 0) { return(0F); } //获取课程下的章节数 var chapters = ChapterAccessor.GetChaptersAllFor(CourseId); //有效的章节(即状态为启用的章节) var effectIds = chapters.Where(p => p.Status == (int)ChapterStatus.ENABLED).Select(p => p.ChapterId); //有效章节的学习数量 var studiedCount = (decimal)effectIds.Intersect(studied).Count(); return((float)Math.Round(studiedCount / effectIds.Count(), 2, MidpointRounding.ToEven)); }
public override void Execute() { var state = State as ChapterStudyStatisticsEventState; Validate(() => { if (state.Chapter == null) { Throw("事件依赖的课程章节对象为NULL。"); } }); if (state != null) { //获取章节的所有父章节 var chapterIds = ChapterAccessor.GetParentsIds(state.Chapter.ChapterId); //包含自身 chapterIds.Add(state.Chapter.ChapterId); ChapterAccessor.AddOnceTimesForStudy(chapterIds); } }
/// <summary> /// 修改章节信息 /// </summary> /// <param name="state">编辑后的数据状态</param> /// <returns></returns> public bool Modify(ChapterModifyState state) { if (state == null) { return(false); } Data.Entity.Chapter parent = null; if (state.ParentId > 0) { parent = ChapterAccessor.Get(state.ParentId); } ThrowExceptionIfValidateFailure(() => { if (CanModify()) { //所属课程 if (!CourseAccessor.Exists(state.CourseId)) { AddBrokenRule(ChapterManageFailureRule.COURSE_NOT_EXISTS); } //有关联父章节时,父章节不存在 if (state.ParentId > 0 && parent == null) { AddBrokenRule(ChapterManageFailureRule.PAREND_NOT_EXISTS); } //标题不能为空 if (string.IsNullOrWhiteSpace(state.Title)) { AddBrokenRule(ChapterManageFailureRule.TITLE_CANNOT_EMPTY); } //内容不能为空 if (string.IsNullOrWhiteSpace(state.Content)) { AddBrokenRule(ChapterManageFailureRule.CONTENT_CANNOT_EMPTY); } } else { AddBrokenRule(ChapterManageFailureRule.CANNOT_MODIFY); } }); bool success = ChapterAccessor.Update( ID, state.CourseId, state.ParentId, ChapterTools.CreateParentPath(parent, ID), state.Title, state.Content, state.Video, state.Status); if (success && (Chapter.CourseId != state.CourseId || Chapter.Status != state.Status)) { ComputeStudyProgress(state.CourseId); } return(success); }
public ChapterManage(long chapterId) { ID = chapterId; Chapter = ChapterAccessor.Get(chapterId); }
/// <summary> /// 获取所有章节层次结构 /// </summary> /// <returns></returns> public List <ChapterTier> GetChapterTiers() { return(ChapterAccessor.GetChapterTiers(ID)); }
/// <summary> /// 实例化<see cref="CourseStudy"/>对象 /// </summary> /// <param name="studentId">学员ID</param> /// <param name="chapterId">学习的课程章节ID</param> public CourseStudy(long studentId, long chapterId) { Chapter = ChapterAccessor.Get(chapterId); Student = UsersAccessor.Get(studentId); }