Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 将更新的数据状态转换为更新后的课程对象
        /// </summary>
        /// <param name="state"></param>
        private Data.Entity.Course TransferNewFor(CourseModifiedState state)
        {
            var editCourse = new Data.Entity.Course();

            editCourse = Course.CopyTo(editCourse);

            editCourse.SubjectId = state.SubjectId;
            editCourse.Title     = state.Title;
            editCourse.Image     = state.Image;
            editCourse.Content   = state.Content;
            editCourse.Remarks   = state.Remarks;
            editCourse.Objective = state.Objective;
            editCourse.Status    = state.Status;

            return(editCourse);
        }