public async Task <bool> EditTestQuestion(int id, EditQuestionDto editQuestionDto)
        {
            var question = await testQuestionRepository.GetQuestion(id);

            question.Question = editQuestionDto.Question;
            var answers = await answersRepository.GetAnswersForQuestion(question.NumberOfIdentification);

            List <string> editAnswers = new List <string>();

            editAnswers.Add(editQuestionDto.OptionA);
            editAnswers.Add(editQuestionDto.OptionB);
            editAnswers.Add(editQuestionDto.OptionC);
            List <bool> correctAnswer = new List <bool>();

            correctAnswer.Add(editQuestionDto.isCorrectA);
            correctAnswer.Add(editQuestionDto.isCorrectB);
            correctAnswer.Add(editQuestionDto.isCorrectC);
            for (int i = 0; i < editAnswers.Count; i++)
            {
                answers[i].Option    = editAnswers[i];
                answers[i].isCorrect = correctAnswer[i];
            }
            if (question == null || editQuestionDto.Question == "")
            {
                return(false);
            }
            testQuestionRepository.Update(question);
            await testQuestionRepository.SaveChangesAsync();

            return(true);
        }
Пример #2
0
        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);
        }