/// <summary> /// 业务数据检测 /// </summary> protected override void Validate() { //课程标题为空时 if (string.IsNullOrWhiteSpace(Title)) { AddBrokenRule(NewCourseFailureRule.TITLE_CANNOT_NULL_OR_EMPTY); } //课程内容为空时 if (string.IsNullOrWhiteSpace(Content)) { AddBrokenRule(NewCourseFailureRule.CONTENT_CANNOT_NULL_OR_EMPTY); } //学习目标为空时 if (string.IsNullOrWhiteSpace(Objective)) { AddBrokenRule(NewCourseFailureRule.OBJECTIVE_CANNOT_NULL_OR_EMPTY); } //所属科目不存在时 if (!SubjectsAccessor.Exists(SubjectId)) { AddBrokenRule(NewCourseFailureRule.SUBJECT_NOT_EXISTS); } //创建课程的用户不存在时 if (!UsersAccessor.Exists(UserId)) { AddBrokenRule(NewCourseFailureRule.CREATER_NOT_EXISTS); } }
protected override void Validate() { //计划制定者不存在 if (!UsersAccessor.Exists(StudyPlan.UserId)) { AddBrokenRule(NewStudyPlanFailureRule.CREATOR_NOT_EXISTS); } //标题为空 if (string.IsNullOrWhiteSpace(StudyPlan.Title)) { AddBrokenRule(NewStudyPlanFailureRule.TITLE_CANNOT_EMPTY); } //标题已存在 if (StudyPlanAccessor.Exists(StudyPlan.Title)) { AddBrokenRule(NewStudyPlanFailureRule.TITLE_CANNOT_REPEAT); } //计划内容说明为空 if (string.IsNullOrWhiteSpace(StudyPlan.Content)) { AddBrokenRule(NewStudyPlanFailureRule.CONTENT_CANNOT_EMPTY); } //未指定学员 if (_studentIds == null || _studentIds.Count() < 1) { AddBrokenRule(NewStudyPlanFailureRule.STUDENTS_CANNOT_EMPTY); } //未指定关联课程 if (_courseIds == null || _courseIds.Count() < 1) { AddBrokenRule(NewStudyPlanFailureRule.COURSE_CANNOT_EMPTY); } //并非所有课程都存在 if (!CourseAccessor.AllExists(_courseIds)) { AddBrokenRule(NewStudyPlanFailureRule.PARTOF_COURSE_NOT_EXSITS); } }
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); } }