// Get the next question in the test for a user. public TestQuestion GetNextTestQuestion(string userName) { var currentTestSet = GetCurrentTestSet(userName); // If no test set then create new test set. if (currentTestSet is null) { currentTestSet = CreateTestSet(userName); } return(_testQuestionRepository.GetAllTestQuestions().Where(t => t.Result.Equals("None") && t.TestSetId == currentTestSet.Id).OrderBy(t => t.Id).FirstOrDefault()); }
public async Task <bool> EditTest(int id, EditTestDto editTestDto) { var test = await testRepository.GetTest(id); if (test == null) { return(false); } if (editTestDto.AutomaticCountTime == true) { var questions = await testQuestionRepository.GetAllTestQuestions(test.Id); test.TimeOfTest = 0; foreach (var question in questions) { if ((int)question.Complexity == 3) { test.TimeOfTest += 5; } else if ((int)question.Complexity == 2) { test.TimeOfTest += 3; } else if ((int)question.Complexity == 1) { test.TimeOfTest += 1; } } test.Name = editTestDto.Name; test.AdditionalInfo = editTestDto.AdditionalInfo; test.TypeOfTest = (TypeOfTest)Int32.Parse(editTestDto.TypeOfTest); test.AutomaticTime = editTestDto.AutomaticCountTime; } else { test.Name = editTestDto.Name; test.AdditionalInfo = editTestDto.AdditionalInfo; test.TimeOfTest = Int32.Parse(editTestDto.TimeOfTest); test.TypeOfTest = (TypeOfTest)Int32.Parse(editTestDto.TypeOfTest); } testRepository.Update(test); await testRepository.SaveChangesAsync(); return(true); }
public async Task <IEnumerable <ShowTestQuestionAnswers> > ShowTestQuestion(int TestId) { var test = await testRepository.GetTest(TestId); if (test == null) { return(null); } var list = new List <ShowTestQuestionAnswers>(); if (test == null) { return(null); } var questions = await testQuestionRepository.GetAllTestQuestions(TestId); if (questions == null) { return(null); } foreach (var testQuestion in questions) { ShowTestQuestionAnswers show = new ShowTestQuestionAnswers(); show.QuestionId = testQuestion.Id.ToString(); show.Question = testQuestion.Question; var answers = await answersRepository.GetAnswersForQuestion(testQuestion.NumberOfIdentification); if (answers == null) { return(null); } foreach (var listAnswers in answers) { show.Option.Add(listAnswers); } list.Add(show); } return(list); }