Esempio n. 1
0
 protected override void Validate()
 {
     if (UserExam == null)
     {
         AddBrokenRule(UserExamMarkingFailureRule.USER_EXAM_NOT_EXISTS);
     }
     else if (Exam == null)
     {
         AddBrokenRule(UserExamMarkingFailureRule.EXAM_TEMPLATE_NOT_EXISTS);
     }
     else if (Student == null)
     {
         AddBrokenRule(UserExamMarkingFailureRule.STUDENT_NOT_EXISTS);
     }
     else if (QuestionSummaryList == null || QuestionSummaryList.Count() < 1)
     {
         AddBrokenRule(UserExamMarkingFailureRule.QUESTION_SUMMARY_EXCEPTION);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 提交阅卷成绩
        /// </summary>
        /// <param name="reviewUserId">阅卷人用户ID</param>
        /// <param name="QuestionScores"></param>
        /// <returns></returns>
        public bool SubmitMarking(long reviewUserId, Dictionary <long, int> QuestionScores)
        {
            ThrowExceptionIfValidateFailure(() =>
            {
                if (!CanMarking())
                {
                    AddBrokenRule(UserExamMarkingFailureRule.STATUS_CANNOT_MARKING);
                }
                else if (QuestionScores == null || QuestionScores.Count() < 1)
                {
                    AddBrokenRule(UserExamMarkingFailureRule.MARKING_QUESTION_SCORES_EXCEPTION);
                }
                else if (QuestionScores.Count() != QuestionSummaryList.Count())
                {
                    AddBrokenRule(UserExamMarkingFailureRule.MARKING_QUESTION_SCORES_EXCEPTION);
                }

                //循环遍历每一题的得分并记录,检测到未提交得分或得分异常时抛出异常
                foreach (var item in QuestionSummaryList)
                {
                    if (!QuestionScores.ContainsKey(item.QuestionId))
                    {
                        AddBrokenRule(UserExamMarkingFailureRule.PARTOF_QUESTION_NO_SCORE);
                        break;
                    }

                    int score = QuestionScores[item.QuestionId];

                    if (score > item.Score)
                    {
                        AddBrokenRule(UserExamMarkingFailureRule.QUESTION_LAST_SCORE_CANNOT_GREATERTHAN_SCORE);
                        break;
                    }

                    item.ActualScore = score;
                }
            });

            //更新用户考卷信息
            userExam.MarkingStatus = (int)ExamMarkingStatus.READED;
            userExam.MarkingTime   = DateTime.Now;
            userExam.Answer        = JsonUtility.JsonSerializeObject(QuestionSummaryList);
            userExam.Total         = QuestionSummaryList.Sum(p => p.ActualScore);

            //调用仓储服务更新
            bool success = ExamUsersAccessor.Update(UserExam);

            if (success)
            {
                //阅卷完成后的通知事件
                var @event = new MarkingCompleteNoticeEvent(new MarkingCompleteNoticeEventState
                {
                    ReviewUser = reviewUserId,
                    Exam       = Exam,
                    UserExam   = UserExam
                });

                eventsChannels.AddEvent(@event);

                eventsChannels.Execute();
            }

            return(success);
        }