public async Task <bool> DeleteTestQuestion(int id)
        {
            var test_question = await testQuestionRepository.GetQuestion(id);

            var test = await testRepository.GetTest(test_question.TestId);

            var question = await testQuestionRepository.GetQuestion(id);

            if (question == null)
            {
                return(false);
            }
            if ((int)test_question.Complexity == 3)
            {
                test.TimeOfTest -= 5;
            }
            else if ((int)test_question.Complexity == 2)
            {
                test.TimeOfTest -= 3;
            }
            else if ((int)test_question.Complexity == 1)
            {
                test.TimeOfTest -= 1;
            }
            question.isDelete = true;
            testRepository.Update(test);
            await testRepository.SaveChangesAsync();

            answersRepository.SetValueIsDeleteOnQuestion(question.NumberOfIdentification);
            testQuestionRepository.Update(question);
            await testQuestionRepository.SaveChangesAsync();

            return(true);
        }
Ejemplo n.º 2
0
        public async Task <UpdatedTestQuestionDto> UpdateQuestion(UpdateTestQuestionDto updateTestQuestionDto)
        {
            TestQuestion testQuestion = await testQuestionRepository.GetByIdAsync(updateTestQuestionDto.Id);

            if (testQuestion == null)
            {
                return(null);
            }

            testQuestion = mapper.Map <TestQuestion>(updateTestQuestionDto);

            testQuestionRepository.Update(testQuestion);
            await unitOfWork.SaveAsync();

            return(mapper.Map <UpdatedTestQuestionDto>(testQuestion));
        }