public async Task <PartialViewResult> ResultNormal(List <VMSiteTestStepNormal> steps) { return(await Task.Run(() => { var validSteps = steps.Where(x => x.QuestionId != 0).ToArray(); VMSiteTestStepNormal userAnswer; var result = new VMSiteTestResult <VMSiteTestResultNormal>(); var data = Repo.GetNormalResults(steps.First().SubjectId); var test = data.First().Question.Test; result.SiteTestTitle = test.Title; result.SiteTestUrl = Url.Action("Details", "SiteTests", new { titleUrl = test.TitleUrl }); result.Results = new VMSiteTestResultNormal[validSteps.Length]; for (int i = 0; i < validSteps.Length; i++) { userAnswer = validSteps[i]; var answer = data.First(x => x.SubjectId == userAnswer.SubjectId); result.Results[i] = new VMSiteTestResultNormal { SubjectTitle = answer.Subject.Title, QuestionText = data.First(x => x.QuestionId == userAnswer.QuestionId).Question.Text, IsCorrect = answer.QuestionId == userAnswer.QuestionId, Step = userAnswer }; var isCorrect = answer.QuestionId == userAnswer.QuestionId; result.BallsCount += userAnswer.BallsSubjectShow + (isCorrect ? userAnswer.BallsGoodRead : 0) + userAnswer.BallsBadRead + (isCorrect ? (test?.Settings?.DefCorrectAnswerBals ?? 15) : 0); } return PartialView("_ResultNormal", result); })); }
public async Task<PartialViewResult> ResultNormal(List<VMSiteTestStepNormal> steps) { return await Task.Run(() => { var validSteps = steps.Where(x => x.QuestionId != 0).ToArray(); SiteTestAnswer answer; VMSiteTestStepNormal userAnswer; var result = new VMSiteTestResult<VMSiteTestResultNormal>(); var data = _repo.GetNormalResults(steps.First().SubjectId); var test = data.First().Question.Test; result.SiteTestTitle = test.Title; result.SiteTestUrl = Url.Action("Details", "SiteTests", new { titleUrl = test.TitleUrl }); result.Results = new VMSiteTestResultNormal[validSteps.Length]; for (int i = 0; i < validSteps.Length; i++) { userAnswer = validSteps[i]; answer = data.First(x => x.SubjectId == userAnswer.SubjectId); result.Results[i] = new VMSiteTestResultNormal { SubjectTitle = answer.Subject.Title, QuestionText = data.First(x => x.QuestionId == userAnswer.QuestionId).Question.Text, IsCorrect = answer.QuestionId == userAnswer.QuestionId, Step = userAnswer }; var isCorrect = answer.QuestionId == userAnswer.QuestionId; result.BallsCount += userAnswer.BallsSubjectShow + (isCorrect ? userAnswer.BallsGoodRead : 0) + userAnswer.BallsBadRead + (isCorrect ? (test?.Settings?.DefCorrectAnswerBals ?? 15) : 0); } return PartialView("_ResultNormal", result); }); }