public void FinishTest(string userId, TestPaper testPaper) { if (string.IsNullOrWhiteSpace(userId)) { throw new ArgumentOutOfRangeException(nameof(userId)); } if (testPaper == null) { throw new ArgumentNullException(nameof(testPaper)); } var user = _cadreInfoRep.GetModelByUserId(userId); if (user == null) { throw new ArgumentOutOfRangeException(nameof(userId)); } var testResult = testPaper.FinishTest(userId); var score = new exam_score() { UserId = user.UserID, UserName = user.UserName, DeptId = user.DeptId, Office = user.Office, Duties = user.Duties, SubjectId = testPaper.SubjectId, TestId = testPaper.Id, StartTime = testPaper.BeginTime, EndTime = testPaper.FinishTime }; var sbWrongDan = new StringBuilder(); var sbWrongDuo = new StringBuilder(); var sbWrongPd = new StringBuilder(); score.Score = 0; foreach (var result in testResult) { if (result.Result) { score.Score += result.Point; } else { switch (result.Question.Type) { case QuestionType.单选题: sbWrongDan.AppendLine(result.Question.Content); sbWrongDan.AppendLine(QuestionOptionsToText(result.Question)); if (result.Answer != null && result.Answer.Options != null && result.Answer.Options.Count > 0) { sbWrongDan.AppendLine("您的答案是:" + string.Join(",", result.Answer.Options)); } else { sbWrongDan.AppendLine("您的答案是:"); } sbWrongDan.AppendLine("正确答案是:" + string.Join(",", result.Question.RightAnswers)); break; case QuestionType.多选题: sbWrongDuo.AppendLine(result.Question.Content); sbWrongDuo.AppendLine(QuestionOptionsToText(result.Question)); if (result.Answer != null && result.Answer.Options != null && result.Answer.Options.Count > 0) { sbWrongDuo.AppendLine("您的答案是:" + string.Join(",", result.Answer.Options)); } else { sbWrongDuo.AppendLine("您的答案是:"); } sbWrongDuo.AppendLine("正确答案是:" + string.Join(",", result.Question.RightAnswers)); break; case QuestionType.判断题: sbWrongPd.AppendLine(result.Question.Content); sbWrongPd.AppendLine(QuestionOptionsToText(result.Question)); if (result.Answer != null && result.Answer.Options != null && result.Answer.Options.Count > 0) { sbWrongPd.AppendLine("您的答案是:" + string.Join(",", result.Answer.Options)); } else { sbWrongPd.AppendLine("您的答案是:"); } sbWrongPd.AppendLine("正确答案是:" + string.Join(",", result.Question.RightAnswers)); break; } } } score.Wrong_Dan = sbWrongDan.ToString(); score.Wrong_Duo = sbWrongDuo.ToString(); score.Wrong_Pd = sbWrongPd.ToString(); //检查是否已经交过卷,同一个人同一门考试只能有一成绩 if (!_examScore.IsFinishedExam(score.TestId, score.UserId)) { //最好事务处理.... _examScore.Add(score); _examTestUserRep.Finish(userId, testPaper.Id); } RemoveFormCache(testPaper.Id, userId); }