Ejemplo n.º 1
0
        /// <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);
            }
        }
Ejemplo n.º 2
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);
        }