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); }
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, }); }
public async Task <bool> Validate(string quizId, QuizSubmit quizSubmit) { return(await quizDao.Validate(quizId, quizSubmit)); }