예제 #1
0
        /// <summary>
        /// 从<see cref="ExamsModifyState"/>对象更新考卷
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public bool ModifyTo(ExamsModifyState state)
        {
            ThrowExceptionIfValidateFailure(() =>
            {
                if (state == null)
                {
                    AddBrokenRule(ExamsManageFailureRule.MODIFYSTATE_OBJECT_IS_NULL);
                }
                else
                {
                    //考卷标题为Empty
                    if (string.IsNullOrWhiteSpace(state.Title))
                    {
                        AddBrokenRule(ExamsManageFailureRule.TITLE_CANNOT_EMPTY);
                    }

                    //该考卷未指定题库
                    var questionCount = state.Questions.SplitToLongArray().Count();
                    if (questionCount < 1)
                    {
                        AddBrokenRule(ExamsManageFailureRule.QUESTIONS_CANNOT_EMPTY);
                    }

                    //及格分不能大于等于总分是不允许的
                    if (state.Pass >= state.Total)
                    {
                        AddBrokenRule(ExamsManageFailureRule.PASS_MUST_LESS_THAN_TO_TOTAL);
                    }

                    //总分及各题分是否一致
                    var totalSum = state.RedioTotal + state.MultipleTotal + state.JudgeTotal + state.FillingTotal + state.AskTotal;
                    if (totalSum != state.Total)
                    {
                        AddBrokenRule(ExamsManageFailureRule.TOTAL_NOT_EQUALS_SUM);
                    }

                    //如果有设置考卷的使用有效时间,则开始时间必须小于结束时间
                    if (state.StartTime.HasValue && state.EndTime.HasValue && state.StartTime.Value >= state.EndTime.Value)
                    {
                        AddBrokenRule(ExamsManageFailureRule.STARTTIME_MUST_BE_BEFORE_THE_ENDTIME);
                    }
                }
            });

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

            return(ExamsAccessor.Update(editExams));
        }
예제 #2
0
        /// <summary>
        /// 生成一个新考卷对象
        /// </summary>
        /// <param name="state"></param>
        private Data.Entity.Exams CreateNewExamsFor(ExamsModifyState state)
        {
            var newExams = new Data.Entity.Exams
            {
                //不可修改内容
                ExamId     = ID,
                Answers    = Exams.Answers,
                CreateTime = Exams.CreateTime,
                Status     = Exams.Status,
                UseCount   = Exams.Status,
                UserId     = Exams.UserId,
                //以下为修改内容
                ExamType      = state.ExamType,
                CourseIds     = state.CourseIds,
                Title         = state.Title,
                Remarks       = state.Remarks,
                Questions     = state.Questions,
                Time          = state.Time,
                Total         = state.Total,
                Pass          = state.Pass,
                Radio         = state.Radio,
                RedioTotal    = state.RedioTotal,
                Multiple      = state.Multiple,
                MultipleTotal = state.MultipleTotal,
                Judge         = state.Judge,
                JudgeTotal    = state.JudgeTotal,
                Filling       = state.Filling,
                FillingTotal  = state.FillingTotal,
                Ask           = state.Ask,
                AskTotal      = state.AskTotal,
                StartTime     = state.StartTime,
                EndTime       = state.EndTime
            };

            return(newExams);
        }