Exemple #1
0
        /// <summary>
        /// 获取解题思路信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="questionType"></param>
        /// <returns></returns>
        public async Task <string> GetQuestionIdeas(int id, string questionType)
        {
            if (questionType == QuestionTypeConst.Judge)
            {
                var question = await _judgeService.FindJudgeById(id);

                return(question.Ideas);
            }
            else
            {
                var question = await _selectService.FindSelectById(id);

                return(question.Ideas);
            }
        }
        /// <summary>
        /// 学生答题
        /// </summary>
        /// <param name="studentId">学生Id</param>
        /// <param name="examQuestionId">考试问题Id</param>
        /// <param name="answer">回答内容</param>
        /// <returns></returns>
        public async Task <StuanswerdetailDto> AnswerQuestionByStudent(
            int studentId,
            int examQuestionId,
            string[] answer)
        {
            // 判断是否已经答题过,避免重复答题
            var isAnswer = await _examquestionRepository.Change <TbStuanswerdetail>()
                           .Where(u => u.StuId == studentId &&
                                  u.QuestionId == examQuestionId)
                           .FirstOrDefaultAsync();

            if (isAnswer != null)
            {
                throw Oops.Oh(ExamAnswerScoreErrorCodes.d2102);
            }

            var examQuestion = await _examquestionRepository
                               .Entities.AsNoTracking()
                               .Where(u => u.Id == examQuestionId)
                               .Select(u => new TbExamquestion
            {
                Id           = u.Id,
                QuestionType = u.QuestionType,
                ExamId       = u.ExamId,
                QuestionId   = u.QuestionId,
                Score        = u.Score,
                Exam         = new TbExam
                {
                    Id       = u.Exam.Id,
                    IsEnable = u.Exam.IsEnable,
                    IsFinish = u.Exam.IsFinish,
                }
            })
                               .FirstOrDefaultAsync();

            if (examQuestion == null || (examQuestion.Exam.IsEnable == "0" || examQuestion.Exam.IsFinish == "1"))
            {
                throw Oops.Oh(ExamAnswerScoreErrorCodes.d2101);
            }

            string[] questionAnswer;
            // 获取题目详情
            if (examQuestion.QuestionType == QuestionTypeConst.Judge)
            {
                var question = await _judgeService.FindJudgeById(examQuestion.QuestionId);

                questionAnswer = question.Answer.Split("、");
            }
            else
            {
                var question = await _selectService.FindSelectById(examQuestion.QuestionId);

                questionAnswer = question.Answer.Split("、");
            }

            // 判断答案是否正确
            var  q       = from a in answer join b in questionAnswer on a equals b select a;
            bool isRight = answer.Length == questionAnswer.Length && q.Count() == answer.Length;

            var stuanswerdetailDto = new StuanswerdetailDto
            {
                StuId        = studentId,
                ExamId       = examQuestion.ExamId,
                QuestionId   = examQuestionId,
                QuestionType = examQuestion.QuestionType,
                Stuanswer    = string.Join("、", answer),
                Answer       = string.Join("、", questionAnswer),
                Isright      = isRight ? "1" : "0",
            };

            // 记录答题
            var stuanswer = await _answerRepository
                            .InsertNowAsync(stuanswerdetailDto.Adapt <TbStuanswerdetail>());

            return(stuanswer.Entity.Adapt <StuanswerdetailDto>());
        }
Exemple #3
0
        /// <summary>
        /// 查询是非题信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <JudgeCourseChapterOutput> GetJudgeInfo(int id)
        {
            var judgeEntity = await _judgeService.FindJudgeById(id);

            return(judgeEntity.Adapt <JudgeCourseChapterOutput>());
        }