예제 #1
0
        /// <summary>
        /// 用户参加考试,返回根据考卷模板生成最终的考试卷
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="examId">准备参考的试卷</param>
        /// <remarks></remarks>
        public NewExamPaper TakeExam(long userId, long examId)
        {
            var examManage   = new ExamsManage(examId);
            var newExamPaper = examManage.CreateNewExamPaper();

            if (newExamPaper != null)
            {
                //将题目信息初始化为作答信息
                var results = newExamPaper.Questions.Select(p => new UserExamQuestionResult(p)).ToList();

                //将新参考试卷到数据库
                UserExamInitRequest request = new UserExamInitRequest
                {
                    UserExamId       = newExamPaper.PaperId,
                    ExamId           = examId,
                    UserId           = userId,
                    CreateTime       = newExamPaper.CreateTime,
                    QuestionsResults = results
                };

                var  userExamInit = new UserExamInit(request);
                bool success      = userExamInit.Save();

                if (success)
                {
                    return(newExamPaper);
                }
            }

            return(null);
        }
예제 #2
0
 /// <summary>
 /// 初始化一个<see cref="UserExamInit"/>对象实例
 /// </summary>
 /// <param name="request"></param>
 public UserExamInit(UserExamInitRequest request)
 {
     if (request != null)
     {
         this.request = request;
         ID           = request.UserExamId;
     }
 }