public async Task <int> PerformChallengeAsync(ChallengedTest test) { var challengeExecutor = new ChallengeExecutor(); test.SourceTest = await _tests.GetByIdAsync(test.SourceTestId); await challengeExecutor.ChallengeAsync(test); return(await _challengedTests.CreateAsync(test)); }
public async Task <ICollection <ChallengedQuestion> > GetByParentTestAsync(ChallengedTest test) { var questions = await Query.Where("ChallengedTestId", test.Id).GetAsync <ChallengedQuestion>(); foreach (var question in questions) { question.ChallengedTest = test; question.SourceQuestion = await _questionRepository.GetByIdAsync(question.SourceQuestionId); question.Answers = await _answerRepository.GetByParentQuestionAsync(question); } return(questions.ToList()); }
public async Task ChallengeAsync(ChallengedTest challengedTest) { var map = from expected in challengedTest.SourceTest.Questions let actual = challengedTest.Questions.First(c => c.SourceQuestionId == expected.Id) select new { Expected = expected, Actual = actual }; var tasks = from pair in map select Task.Run(() => CheckQuestion(pair.Expected, pair.Actual)); await Task.WhenAll(tasks); challengedTest.MaximumScore = challengedTest.Questions.Sum(q => q.TotalScore); challengedTest.UserScore = challengedTest.Questions.Sum(q => q.UserScore); }