public async Task <int> CheckTest(string id, List <ListOfTestQuestions> listOfTestQuestions) { var score = 0; if (listOfTestQuestions == null) { return(score); } var type_test = await testRepository.GetTest(Int32.Parse(id)); var infoForResult = await testQuestionRepository.GetQuestion(Int32.Parse(listOfTestQuestions[0].QuestionId)); var testName = await testRepository.GetTest(infoForResult.TestId); var maxScore = await CountMaxScoreOfTest(listOfTestQuestions); for (var i = 0; i < listOfTestQuestions.Count; i++) { var question = await testQuestionRepository.GetQuestion(Int32.Parse(listOfTestQuestions[i].QuestionId)); if (question.Id == Int32.Parse(listOfTestQuestions[i].QuestionId)) { var answers = await answersRepository.GetAnswersForQuestion(question.NumberOfIdentification); if ((int)type_test.TypeOfTest == 0) { if (listOfTestQuestions[i].isCorrectA == answers[0].isCorrect && listOfTestQuestions[i].isCorrectB == answers[1].isCorrect && listOfTestQuestions[i].isCorrectC == answers[2].isCorrect) { if ((int)question.Complexity == 1) { score += 5; } else if ((int)question.Complexity == 2) { score += 10; } else if ((int)question.Complexity == 3) { score += 15; } } else if (listOfTestQuestions[i].isCorrectA == answers[0].isCorrect == true || listOfTestQuestions[i].isCorrectB == answers[1].isCorrect == true || listOfTestQuestions[i].isCorrectC == answers[2].isCorrect == true) { if ((int)question.Complexity == 1) { score += 2; } else if ((int)question.Complexity == 2) { score += 5; } else if ((int)question.Complexity == 3) { score += 7; } } } else if ((int)type_test.TypeOfTest == 1) { if (listOfTestQuestions[i].isCorrectA == answers[0].isCorrect && listOfTestQuestions[i].isCorrectB == answers[1].isCorrect && listOfTestQuestions[i].isCorrectC == answers[2].isCorrect) { if ((int)question.Complexity == 1) { score += 5; } else if ((int)question.Complexity == 2) { score += 10; } else if ((int)question.Complexity == 3) { score += 15; } } } } } var result = new Results(Int32.Parse(listOfTestQuestions[0].UserId), infoForResult.TestId, infoForResult.SubjectId, (score * 100) / maxScore, testName.Name); resultsRepository.Create(result); await resultsRepository.SaveChangesAsync(); return(score); }