Exemple #1
0
        /// <summary>
        /// 获取计划中的课程集合
        /// </summary>
        /// <returns></returns>
        private List <CourseInfo> GetCourses()
        {
            ThrowExceptionIfValidateFailure();

            var tempCourses = new List <CourseInfo>();

            //学习计划中的课程集合
            var planCourses = StudyPlanCourseAccessor.GetCourseList(ID);

            //课程ID集合
            var courseIds = planCourses.Select(p => p.CourseId).ToArray();

            //获取课程信息集合
            var coursesList = CourseAccessor.GetList(courseIds);

            foreach (var course in coursesList)
            {
                var planCourse = planCourses.FirstOrDefault(p => p.CourseId == course.CourseId);

                tempCourses.Add(new CourseInfo
                {
                    CourseId  = course.CourseId,
                    Title     = course.Title,
                    Content   = course.Content,
                    Image     = course.Image,
                    Objective = course.Objective,
                    Remarks   = course.Remarks,
                    Sort      = planCourse.Sort,
                    Status    = course.Status,
                    SubjectId = course.SubjectId
                });
            }

            return(tempCourses);
        }
Exemple #2
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);
            }
        }
Exemple #3
0
        /// <summary>
        /// 获取并转换为<see cref="QuestionDetails"/>类型数据对象
        /// </summary>
        /// <returns></returns>
        public QuestionDetails ConvertToQuestionDetails()
        {
            if (Question == null)
            {
                return(null);
            }

            //科目名称
            var subjectName = SubjectsAccessor.GetName(Question.SubjectId);
            //课程标题
            var courseTitle = CourseAccessor.GetTitle(Question.CourseId);

            var details = new QuestionDetails
            {
                QuestionId  = Question.QuestionId,
                Answer      = QuestionTools.DeserializeAnswers(Question.Answer, Question.Type),
                Count       = Question.Count,
                CourseId    = Question.CourseId,
                CourseTitle = courseTitle,
                CreateTime  = Question.CreateTime,
                LastTime    = Question.LastTime,
                Marking     = Question.Marking,
                Status      = Question.Status,
                SubjectId   = Question.SubjectId,
                SubjectName = subjectName,
                Topic       = Question.Topic,
                Type        = Question.Type,
                UserId      = Question.UserId
            };

            return(details);
        }
Exemple #4
0
        /// <summary>
        /// 校正对象属性
        /// </summary>
        public void ReviseProperty()
        {
            var course = CourseAccessor.Get(CourseId);

            if (course != null)
            {
                SubjectId = course.SubjectId;
            }
        }
Exemple #5
0
        /// <summary>
        /// 获取指定状态的所有课程ID及对应名称集合
        /// </summary>
        /// <param name="status"></param>
        /// <returns></returns>
        public List <IdNameResponse> GetAllCourseIdNameList(int?status = null)
        {
            var data = CourseAccessor.GetAllIdTitles(status);

            return(data.Select(p => new IdNameResponse
            {
                Id = p.Key,
                Name = p.Value
            }).ToList());
        }
Exemple #6
0
        /// <summary>
        /// 修改信息
        /// </summary>
        /// <param name="state">将要修改后的状态</param>
        /// <returns></returns>
        public bool ModifyTo(CourseModifiedState state)
        {
            if (state == null)
            {
                return(false);
            }

            ThrowExceptionIfValidateFailure(() =>
            {
                //是否允许被编辑
                if (CanModify())
                {
                    //课程标题为空时
                    if (string.IsNullOrWhiteSpace(state.Title))
                    {
                        AddBrokenRule(CourseManageFailureRule.TITLE_CANNOT_NULL_OR_EMPTY);
                    }

                    //课程内容为空时
                    if (string.IsNullOrWhiteSpace(state.Content))
                    {
                        AddBrokenRule(CourseManageFailureRule.CONTENT_CANNOT_NULL_OR_EMPTY);
                    }

                    //学习目标为空时
                    if (string.IsNullOrWhiteSpace(state.Objective))
                    {
                        AddBrokenRule(CourseManageFailureRule.OBJECTIVE_CANNOT_NULL_OR_EMPTY);
                    }

                    //所属科目不存在时
                    if (!SubjectsAccessor.Exists(state.SubjectId))
                    {
                        AddBrokenRule(CourseManageFailureRule.SUBJECT_NOT_EXISTS);
                    }
                }
                else
                {
                    AddBrokenRule(CourseManageFailureRule.CANNOT_MODIFY);
                }
            });

            //映射数据实体对象后存储
            var editCourse = TransferNewFor(state);

            bool success = CourseAccessor.Update(editCourse);

            if (success && Course.Status != state.Status)
            {
                ComputeStudyProgress(ID);
            }

            return(success);
        }
Exemple #7
0
        /// <summary>
        /// 执行搜索
        /// </summary>
        public PagerModel <Data.Entity.Course> Search()
        {
            this.ThrowExceptionIfValidateFailure();

            PagerModel <Data.Entity.Course> pager = new PagerModel <Data.Entity.Course>()
            {
                Index = PageIndex,
                Size  = PageSize
            };

            CourseAccessor.Get(pager, Keyword, subjectId: SubjectId, status: Status);

            return(pager);
        }
Exemple #8
0
        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);
            }
        }
Exemple #9
0
        /// <summary>
        /// 设置为“禁用”状态
        /// </summary>
        /// <returns></returns>
        public bool SetDisable()
        {
            ThrowExceptionIfValidateFailure(() =>
            {
                if (!CanSetToDisable())
                {
                    AddBrokenRule(CourseManageFailureRule.STATUS_CANNOT_SET_TO_DISABLED);
                }
            });

            bool success = CourseAccessor.SetStatus(ID, (int)CourseStatus.DISABLED);

            if (success)
            {
                ComputeStudyProgress(ID);
            }

            return(success);
        }
Exemple #10
0
        public bool Save()
        {
            ThrowExceptionIfValidateFailure();

            Data.Entity.Course course = new Data.Entity.Course
            {
                CourseId   = ID,
                UserId     = UserId,
                SubjectId  = SubjectId,
                Title      = Title,
                Content    = Content,
                Objective  = Objective,
                Image      = Image,
                Remarks    = Remarks,
                Status     = Status,
                CreateTime = DateTime.Now
            };

            return(CourseAccessor.Insert(course));
        }
        public override void Execute()
        {
            Validate();

            //需要计算学习进度的学员及计划
            var studentsPlans = GetStuentPlans();

            //获取计划中的所有课程ID
            var allCourses = GetCourseIdsFor(studentsPlans?.Values);

            //所有课程对应的章节集合
            var courseChapters = CourseAccessor.GetCourseChaptersFor(allCourses);

            List <UserStudyPlanProgressModel> studentProgressList = new List <UserStudyPlanProgressModel>();

            if (studentsPlans == null)
            {
                return;
            }

            foreach (var item in studentsPlans)
            {
                //用户该课程相关的学习计划进度计算结果
                Dictionary <long, float> planProgressResult = CalculatePlanProgress(item.Key, item.Value, courseChapters);

                foreach (var result in planProgressResult)
                {
                    studentProgressList.Add(new UserStudyPlanProgressModel
                    {
                        StudentId = item.Key,
                        PlanId    = result.Key,
                        Progress  = result.Value,
                        Status    = (int)GetStatusFor(result.Value)
                    });
                }
            }

            //更新学习计划进度
            UserStudyPlanAccessor.UpdateProgress(studentProgressList);
        }
Exemple #12
0
 /// <summary>
 /// 获取课程标题
 /// </summary>
 /// <returns></returns>
 public string GetCourseTitle()
 {
     return(CourseAccessor.GetTitle(Chapter.CourseId));
 }
Exemple #13
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);
        }
Exemple #14
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));
        }
Exemple #15
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);
            }
        }