コード例 #1
0
        public async Task UpdateQuestion()
        {
            if (SelectedTest == null)
            {
                MessageBox.Show("Please select a test to take");
            }
            else
            {
                IQuestionService questionService = new QuestionDataService();
                ITestService     testService     = new TestDataService();
                Test             selectedTest    = await testService.Get(SelectedTest.Id);

                IEnumerable <Question> selectedTestQuestions = await questionService.GetAllQuestionsForGivenTestName(selectedTest.TestName);

                if (selectedTest.TotalMark != selectedTestQuestions.Select(q => q.QuestionMark).Sum())
                {
                    MessageBox.Show("This test needs more questions in order to be eligible to be taken.");
                }
                else
                {
                    SelectedTest             = selectedTest;
                    QuestionName             = (selectedTest.Questions.ToList())[CurrentQuestion].QuestionText;
                    QuestionText             = (selectedTest.Questions.ToList())[CurrentQuestion].QuestionText;
                    QuestionOptions          = (selectedTest.Questions.ToList())[CurrentQuestion].QuestionOptions.ToList();
                    ListVisibility           = Visibility.Collapsed;
                    DescriptionVisibility    = Visibility.Collapsed;
                    MainVisibility           = Visibility.Visible;
                    CreateQuestionVisibility = Visibility.Collapsed;
                }
            }
        }
コード例 #2
0
 public DependencyInjector()
 {
     _dbc = new DataBaseConnector();
     _pds = new PlayerDataService(_dbc);
     _lds = new LevelDataService(_dbc);
     _qds = new QuestionDataService(_dbc);
     _lst = new LevelSuccessTimeService(_dbc);
 }
コード例 #3
0
        private async void FuncToCall3(object context)
        {
            if (QuestionTextForNewTest == null || QuestionTextForNewTest == "")
            {
                MessageBox.Show("Please populate the question text field");
            }
            else if (FirstOptionForNewTest == null || FirstOptionForNewTest == "")
            {
                MessageBox.Show("Please populate the first option text field");
            }
            else if (SecondOptionForNewTest == null || SecondOptionForNewTest == "")
            {
                MessageBox.Show("Please populate the second option text field");
            }
            else if (ThirdOptionForNewTest == null || ThirdOptionForNewTest == "")
            {
                MessageBox.Show("Please populate the third option text field");
            }
            else if (FourthOptionForNewTest == null || FourthOptionForNewTest == "")
            {
                MessageBox.Show("Please populate the fourth option text field");
            }
            else if (SelectedTestForNewQuestion == null || SelectedTestForNewQuestion == "")
            {
                MessageBox.Show("Please select an associated test for this question");
            }
            else if (CorrectAnswerForNewTest == null || CorrectAnswerForNewTest == "")
            {
                MessageBox.Show("Please populate the correct answer text field");
            }
            else
            {
                Question newQuestion = new Question()
                {
                    QuestionText  = QuestionTextForNewTest,
                    CorrectAnswer = CorrectAnswerForNewTest,
                    QuestionMark  = 10,
                };

                IQuestionService       questionService       = new QuestionDataService();
                ITestService           testService           = new TestDataService();
                IEnumerable <Question> selectedTestQuestions = await questionService.GetAllQuestionsForGivenTestName(SelectedTestForNewQuestion);

                if (selectedTestQuestions.Count() > 0)
                {
                    if (selectedTestQuestions.ToList()[0].Test.TotalMark == selectedTestQuestions.Select(q => q.QuestionMark).Sum())
                    {
                        MessageBox.Show("This test cannot support any more questions (maximum score reached).");
                    }
                    else
                    {
                        await questionService.CreateNewQuestion(newQuestion, SelectedTestForNewQuestion, FirstOptionForNewTest, SecondOptionForNewTest, ThirdOptionForNewTest, FourthOptionForNewTest);
                    }
                }
                else
                {
                    await questionService.CreateNewQuestion(newQuestion, SelectedTestForNewQuestion, FirstOptionForNewTest, SecondOptionForNewTest, ThirdOptionForNewTest, FourthOptionForNewTest);
                }
                QuestionTextForNewTest     = null;
                FirstOptionForNewTest      = null;
                SecondOptionForNewTest     = null;
                ThirdOptionForNewTest      = null;
                FourthOptionForNewTest     = null;
                SelectedTestForNewQuestion = null;
                CorrectAnswerForNewTest    = null;
            }
        }