private static void InsertMissingDifficulties(IEnumerable <OpenTriviaDb.Result> validQuestions) { foreach (var difficulty in validQuestions.Select(r => r.Difficulty)) { if (QuestionDifficulty.Select(difficulty) == null) { var newDifficulty = new QuestionDifficulty { Name = difficulty }; newDifficulty.Insert(); } } }
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); } } }
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(); }
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(); } }