Ejemplo n.º 1
0
        protected override void Validate()
        {
            //所属课程
            if (!CourseAccessor.Exists(CourseId))
            {
                AddBrokenRule(NewChapterFailureRule.COURSE_NOT_EXISTS);
            }

            //有关联父章节时的验证
            if (ParentId > 0)
            {               //父章节不存在
                if (ParentChapter == null)
                {
                    AddBrokenRule(NewChapterFailureRule.PAREND_NOT_EXISTS);
                }
            }

            //标题不能为空
            if (string.IsNullOrWhiteSpace(Title))
            {
                AddBrokenRule(NewChapterFailureRule.TITLE_CANNOT_EMPTY);
            }

            //内容不能为空
            if (string.IsNullOrWhiteSpace(Content))
            {
                AddBrokenRule(NewChapterFailureRule.CONTENT_CANNOT_EMPTY);
            }
        }
Ejemplo n.º 2
0
        public bool ModifyTo(QuestionModifyState state)
        {
            ThrowExceptionIfValidateFailure(() =>
            {
                if (state == null)
                {
                    AddBrokenRule(QuestionEditFailureRule.MODIFY_STATE_CANNOT_EMPTY);
                }
                else if (CanModify())
                {
                    //题目所属课程不存在
                    if (!CourseAccessor.Exists(state.CourseId))
                    {
                        AddBrokenRule(QuestionEditFailureRule.COURSE_NOT_EXISTS);
                    }

                    //题目类型无效
                    if (!((IList)Enum.GetValues(typeof(QuestionType))).Contains((QuestionType)state.Type))
                    {
                        AddBrokenRule(QuestionEditFailureRule.QUESTION_TYPE_ERROR);
                    }

                    //题目标题不能为空
                    if (string.IsNullOrWhiteSpace(state.Topic))
                    {
                        AddBrokenRule(QuestionEditFailureRule.TOPIC_CANNOT_EMPTY);
                    }

                    // 如果->非问答题且答案项为NULL,则抛出错误;
                    // 否则->题目类型与答案项进能校验,校验规则如下:
                    //  1、匹配,则验证答案项设置是否有效
                    //  2、不匹配,则添加业务错误
                    if (state.Type != (int)QuestionType.ESSAY_QUESTION && state.AnswerOptions == null)
                    {
                        AddBrokenRule(QuestionEditFailureRule.ANSWER_OPTIONS_CANNOT_EMPTY);
                    }
                    else if (QuestionTools.CheckAnswerOptionsType(state.AnswerOptions, state.Type))
                    {
                        //题目的答案项验证失败
                        if (!state.AnswerOptions.Validate())
                        {
                            if (state.AnswerOptions is SingleChoiceAnswer)
                            {
                                AddBrokenRule(QuestionEditFailureRule.SINGLE_CHOICE_ANSWER_OPTIONS_ERROR);
                            }
                            else if (state.AnswerOptions is MultipleChoiceAnswer)
                            {
                                AddBrokenRule(QuestionEditFailureRule.MULTIPLE_CHOICE_ANSWER_OPTIONS_ERROR);
                            }
                            else if (state.AnswerOptions is TrueFalseAnswer)
                            {
                                AddBrokenRule(QuestionEditFailureRule.TRUE_FALSE_ANSWER_OPTIONS_ERROR);
                            }
                            else if (state.AnswerOptions is GapFillingAnswer)
                            {
                                AddBrokenRule(QuestionEditFailureRule.GAP_FILLING_ANSWER_OPTIONS_ERROR);
                            }
                        }
                    }
                    else
                    {
                        AddBrokenRule(QuestionEditFailureRule.QUESTION_TYPE_AND_ANSWER_OPTIONS_REGEX_FAILURE);
                    }
                }
                else
                {
                    AddBrokenRule(QuestionEditFailureRule.CANNOT_EDIT);
                }
            });

            if (state.SubjectId == 0)
            {
                state.ReviseProperty();
            }


            return(QuestionsAccessor.Update(
                       ID,
                       state.CourseId,
                       state.SubjectId,
                       state.Type,
                       state.Marking,
                       state.Topic,
                       state.Answer,
                       state.Status));
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
        protected override void Validate()
        {
            //题目创建用户不存在
            if (!UsersAccessor.Exists(UserId))
            {
                AddBrokenRule(NewQuestionFailureRule.QUESTION_CREATOR_NOT_EXISTS);
            }

            //题目所属课程不存在
            if (!CourseAccessor.Exists(CourseId))
            {
                AddBrokenRule(NewQuestionFailureRule.COURSE_NOT_EXISTS);
            }

            //题目类型无效
            if (!((IList <int>)Enum.GetValues(typeof(QuestionType))).Contains(Type))
            {
                AddBrokenRule(NewQuestionFailureRule.QUESTION_TYPE_ERROR);
            }

            //题目标题不能为空
            if (string.IsNullOrWhiteSpace(Topic))
            {
                AddBrokenRule(NewQuestionFailureRule.TOPIC_CANNOT_EMPTY);
            }

            // 如果->非问答题且答案项为NULL,则抛出错误;
            // 否则->题目类型与答案项进能校验,校验规则如下:
            //  1、匹配,则验证答案项设置是否有效
            //  2、不匹配,则添加业务错误
            if (Type != (int)QuestionType.ESSAY_QUESTION && AnswerOptions == null)
            {
                AddBrokenRule(NewQuestionFailureRule.ANSWER_OPTIONS_CANNOT_EMPTY);
            }
            else if (QuestionTools.CheckAnswerOptionsType(AnswerOptions, Type))
            {
                //题目的答案项验证失败
                if (!AnswerOptions.Validate())
                {
                    if (AnswerOptions is SingleChoiceAnswer)
                    {
                        AddBrokenRule(NewQuestionFailureRule.SINGLE_CHOICE_ANSWER_OPTIONS_ERROR);
                    }
                    else if (AnswerOptions is MultipleChoiceAnswer)
                    {
                        AddBrokenRule(NewQuestionFailureRule.MULTIPLE_CHOICE_ANSWER_OPTIONS_ERROR);
                    }
                    else if (AnswerOptions is TrueFalseAnswer)
                    {
                        AddBrokenRule(NewQuestionFailureRule.TRUE_FALSE_ANSWER_OPTIONS_ERROR);
                    }
                    else if (AnswerOptions is GapFillingAnswer)
                    {
                        AddBrokenRule(NewQuestionFailureRule.GAP_FILLING_ANSWER_OPTIONS_ERROR);
                    }
                }
            }
            else
            {
                AddBrokenRule(NewQuestionFailureRule.QUESTION_TYPE_AND_ANSWER_OPTIONS_REGEX_FAILURE);
            }
        }