コード例 #1
0
        private static void InsertMissingTypes(IEnumerable <OpenTriviaDb.Result> validQuestions)
        {
            foreach (var type in validQuestions.Select(r => r.Type))
            {
                if (QuestionType.Select(type) == null)
                {
                    var newQuestionType = new QuestionType
                    {
                        Name = type
                    };

                    newQuestionType.Insert();
                }
            }
        }
コード例 #2
0
        private void btnGenerateRandomQuestion_Click(object sender, EventArgs e)
        {
            var selectedDifficulty = QuestionDifficulty.Select(cmbDifficulty.SelectedValue.ToString());
            var selectedType       = QuestionType.Select(cmbType.SelectedValue.ToString());

            if (selectedDifficulty != null && selectedType != null)
            {
                try
                {
                    _currentQuestion = Question.GetRandomQuestion(selectedDifficulty.Id, selectedType.Id);
                    txtCategory.Text = _currentQuestion.Category.Name;
                    rchQuestion.Text = _currentQuestion.QuestionText;
                    rchAnswer.Text   = _currentQuestion.GetAnswer();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
                }
            }
            else if (selectedDifficulty != null)
            {
                try
                {
                    _currentQuestion = Question.GetRandomQuestionByDifficulty(selectedDifficulty.Id);
                    txtCategory.Text = _currentQuestion.Category.Name;
                    rchQuestion.Text = _currentQuestion.QuestionText;
                    rchAnswer.Text   = _currentQuestion.GetAnswer();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
                }
            }
            else if (selectedType != null)
            {
                try
                {
                    _currentQuestion = Question.GetRandomQuestionByType(selectedType.Id);
                    txtCategory.Text = _currentQuestion.Category.Name;
                    rchQuestion.Text = _currentQuestion.QuestionText;
                    rchAnswer.Text   = _currentQuestion.GetAnswer();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
                }
            }
        }
コード例 #3
0
        private void FillFormData()
        {
            var locationList = Business.Entities.Location.Select().ToList();

            cmbLocation.DataSource = locationList.Select(l => l.Name).ToList();
            cmbLocation.Update();

            var difficultyList = QuestionDifficulty.Select().Select(q => q.Name).ToList();

            cmbDifficulty.DataSource = difficultyList;
            cmbDifficulty.Update();

            var typeList = QuestionType.Select().Select(q => q.Name).ToList();

            cmbType.DataSource = typeList;
            cmbType.Update();
        }
コード例 #4
0
        private static void CreateNewQuestions(IEnumerable <OpenTriviaDb.Result> validQuestions)
        {
            foreach (var question in validQuestions)
            {
                var type       = QuestionType.Select(question.Type);
                var difficulty = QuestionDifficulty.Select(question.Difficulty);
                var category   = Category.Select(question.Category);
                var answers    = CreateAnswerKey(question);

                var newQuestion = new Question
                {
                    Category     = category,
                    Difficulty   = difficulty,
                    QuestionText = question.Question,
                    Type         = type,
                    Answer       = answers
                };

                newQuestion.Insert();
            }
        }