예제 #1
0
        public async Task <bool> Validate(string quizId, QuizSubmit quizSubmit)
        {
            var option = await dbContext.QuizOptions.Select(o => new QuizOption
            {
                Correct = o.Correct,
                Id      = o.Id,
                QuizId  = o.QuizId
            }).SingleOrDefaultAsync(o => o.QuizId == quizId && o.Id == quizSubmit.OptionId);

            return(option.Correct.HasValue && option.Correct.Value);
        }
예제 #2
0
        public async Task <QuizValidation> Validate([FromBody] QuizSubmit quizSubmit)
        {
            RaiseIfNotLoggedIn();
            RaiseIfTimeOut();
            var currQuestionId = sessionUtils.GetString(HttpContext, CurrQuestionId);
            var currScore      = sessionUtils.GetInt(HttpContext, CurrScore);

            if (currQuestionId == null || !currScore.HasValue)
            {
                throw new UserException("不在答题状态!");
            }
            var correct = await quizService.Validate(currQuestionId, quizSubmit);

            if (correct)
            {
                sessionUtils.SetInt(HttpContext, CurrScore, currScore.Value + ScoreForEach);
                ResetStartTime();
            }
            return(new QuizValidation
            {
                Correct = correct,
            });
        }
예제 #3
0
 public async Task <bool> Validate(string quizId, QuizSubmit quizSubmit)
 {
     return(await quizDao.Validate(quizId, quizSubmit));
 }