コード例 #1
0
ファイル: NewChapter.cs プロジェクト: jonfee/Teamcores
        /// <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);
        }
コード例 #2
0
ファイル: ChapterManage.cs プロジェクト: jonfee/Teamcores
        /// <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);
        }