Example #1
0
        /// <summary>
        /// 执行考试任务
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <bool> ExecuteExamJob(int id)
        {
            var examJob = await _repository.Entities.AsNoTracking()
                          .Select(u => new TbExamjobs
            {
                Id     = u.Id,
                ExamId = u.ExamId,
                Status = u.Status,
                Exam   = new TbExam
                {
                    Id        = u.Exam.Id,
                    ExamName  = u.Exam.ExamName,
                    StartTime = u.Exam.StartTime,
                    EndTime   = u.Exam.EndTime,
                    Duration  = u.Exam.Duration,
                    IsEnable  = u.Exam.IsEnable,
                    IsFinish  = u.Exam.IsFinish,
                }
            })
                          .FirstOrDefaultAsync(u => u.Id == id);

            if (examJob == null)
            {
                return(false);
            }
            // 判断是否可以启用试卷
            var nowTime = DateTimeOffset.Now;

            if (nowTime >= examJob.Exam.StartTime && examJob.Exam.IsEnable == "0")
            {
                await _examService.EnableExamById(examJob.ExamId);
            }
            // 判断是否结束考试
            if (nowTime >= examJob.Exam.EndTime && examJob.Exam.IsFinish == "0")
            {
                await FinshExamJob(examJob.ExamId);
            }
            return(true);
        }