示例#1
0
        public IHttpActionResult PostQuestion([FromBody] QuestionsBank questionsBank)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest("Invalid data."));
                }

                using (var botContext = new BotDBContext())
                {
                    botContext.QuestionsBank.Add(new QuestionsBank()
                    {
                        Question = questionsBank.Question
                    });

                    botContext.SaveChanges();
                }

                return(Ok("Success"));
            }
            catch (Exception ex)
            {
                LogWorker logworker = new LogWorker("QuestionsBankController", "PostQuestion", ex.ToString());
                return(InternalServerError());
            }
        }
示例#2
0
        private List <Result> getResult()
        {
            List <Result> result = new List <Result>();

            for (int i = 1; i <= 10; i++)
            {
                TextBlock textblockId = (TextBlock)FindName(String.Format("question{0}Id", i.ToString()));
                int       quesId      = Convert.ToInt32(textblockId.Text);

                ComboBox comboBox = (ComboBox)FindName("answer" + i.ToString());
                var      answer   = (comboBox.SelectedValue == null) ? "" : comboBox.SelectedValue.ToString();

                QuestionsBank question = greDatabase.GetQuestion(quesId);
                question.NumberOfTimeAsked += 1;

                Words word = greDatabase.GetWord(question.WordId.Value);
                if (word != null)
                {
                    word.NumOfTimeTested += 1;
                }

                Result res = new Result();

                if (answer == question.Answer)
                {
                    if (word != null)
                    {
                        word.NumOfTimeAccurate += 1;
                        word.Accuracy           = Math.Round((Convert.ToDecimal((double)word.NumOfTimeAccurate / (double)word.NumOfTimeTested) * 100), 2);
                    }
                    question.NumOfCorrectAns += 1;
                    question.Accuracy         = Math.Round((Convert.ToDecimal((double)question.NumOfCorrectAns / (double)question.NumberOfTimeAsked) * 100), 2);
                    res.QuestionId            = quesId;
                    res.Question              = question.Question;
                    res.CorrectAnswer         = question.Answer;
                    res.Answered              = answer;
                    res.Correct = true;
                }
                else
                {
                    if (word != null)
                    {
                        word.Accuracy = Math.Round((Convert.ToDecimal((double)word.NumOfTimeAccurate / (double)word.NumOfTimeTested) * 100), 2);
                    }
                    question.Accuracy = Math.Round((Convert.ToDecimal((double)question.NumOfCorrectAns / (double)question.NumberOfTimeAsked) * 100), 2);
                    res.QuestionId    = quesId;
                    res.Question      = question.Question;
                    res.CorrectAnswer = question.Answer;
                    res.Answered      = answer;
                    res.Correct       = false;
                }
                result.Add(res);
                greDatabase.UpdateQuestion(question);
                greDatabase.UpdateWord(word);
            }
            return(result);
        }
 //Deltes question from the db
 private void DeleteQuestion_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Are you sure you want to delete the record?", "GRE Vocabulary List", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
     {
         var           item     = (sender as Button).DataContext;
         QuestionsBank quesBank = (QuestionsBank)item;
         int           quesId   = quesBank.QuestionID;
         greDatabase.DeleteQuestion(quesId);
         List <QuestionsBank> ques = greDatabase.GetAllQuestions();
         questionListView.ItemsSource = ques;
         MessageBox.Show("Successfully deleted from the question bank!", "GRE Vocabulary List", MessageBoxButton.OK, MessageBoxImage.Information);
     }
 }
        private void EditQuestion_Click(object sender, RoutedEventArgs e)
        {
            var           item     = (sender as Button).DataContext;
            QuestionsBank quesBank = (QuestionsBank)item;

            questionId.Text = quesBank.QuestionID.ToString();
            question.Text   = quesBank.Question;
            option1.Text    = quesBank.Option1;
            option2.Text    = quesBank.Option2;
            option3.Text    = quesBank.Option3;
            option4.Text    = quesBank.Option4;
            if (quesBank.Option1 == quesBank.Answer)
            {
                answer.SelectedValue = "Option1";
            }
            else if (quesBank.Option2 == quesBank.Answer)
            {
                answer.SelectedValue = "Option2";
            }
            else if (quesBank.Option3 == quesBank.Answer)
            {
                answer.SelectedValue = "Option3";
            }
            else if (quesBank.Option4 == quesBank.Answer)
            {
                answer.SelectedValue = "Option4";
            }
            questionTabView.SelectedIndex = 0;
            if (quesBank.WordId.HasValue && quesBank.WordId != 0)
            {
                Words word = greDatabase.GetWord(quesBank.WordId.Value);
                wordIdTextBox.Text   = word.WordId.ToString();
                wordTextBox.Text     = word.Word;
                quesBelong.IsChecked = false;
            }
            else
            {
                wordTextBox.Text     = "";
                wordIdTextBox.Text   = "";
                quesBelong.IsChecked = true;
            }

            addQuestion.Content = "Update question";
            cancel.Visibility   = Visibility.Visible;
        }
        private void AddQuestion_Click(object sender, RoutedEventArgs e)
        {
            var quesId = questionId.Text;
            var ques   = question.Text;
            var opt1   = option1.Text;
            var opt2   = option2.Text;
            var opt3   = option3.Text;
            var opt4   = option4.Text;

            if (ques == "")
            {
                MessageBox.Show("Question textbox can not be empty.", "GRE Vocabulary List", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else if (ques.Contains("'"))
            {
                MessageBox.Show("Question can not contain '. Please remove ' and resubmit.", "GRE Vocabulary List", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else if (opt1 == "")
            {
                MessageBox.Show("Option1 textbox can not be empty.", "GRE Vocabulary List", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else if (opt2 == "")
            {
                MessageBox.Show("option2 textbox can not be empty.", "GRE Vocabulary List", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else if (opt3 == "")
            {
                MessageBox.Show("Option3 textbox can not be empty.", "GRE Vocabulary List", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else if (opt4 == "")
            {
                MessageBox.Show("Option4 textbox can not be empty.", "GRE Vocabulary List", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                var ans = answer.SelectedValue.ToString();
                if (ans == "Option1")
                {
                    ans = opt1;
                }
                else if (ans == "Option2")
                {
                    ans = opt2;
                }
                else if (ans == "Option3")
                {
                    ans = opt3;
                }
                else if (ans == "Option4")
                {
                    ans = opt4;
                }
                else
                {
                    MessageBox.Show("Select the correct answer for this question.", "GRE Vocabulary List", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                if (MessageBox.Show("Have you selected the right answer for this question?", "GRE Vocabulary List", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                {
                    if (quesId == "")
                    {
                        QuestionsBank quesBank = new QuestionsBank();
                        quesBank.Question          = ques;
                        quesBank.Option1           = opt1;
                        quesBank.Option2           = opt2;
                        quesBank.Option3           = opt3;
                        quesBank.Option4           = opt4;
                        quesBank.Answer            = ans;
                        quesBank.NumberOfTimeAsked = 0;
                        quesBank.NumOfCorrectAns   = 0;
                        quesBank.Accuracy          = 0;
                        if (quesBelong.IsChecked == false)
                        {
                            quesBank.WordId = Convert.ToInt32(wordIdTextBox.Text);
                        }
                        else
                        {
                            Words word = (Words)((MainWindow)Application.Current.MainWindow).wordListView.SelectedValue;
                            wordIdTextBox.Text = word.WordId.ToString();
                            wordTextBox.Text   = word.Word;
                        }
                        greDatabase.SubmitQuestion(quesBank);
                        MessageBox.Show("Successfully added to the question bank!", "GRE Vocabulary List", MessageBoxButton.OK, MessageBoxImage.Information);
                        questionId.Text      = "";
                        question.Text        = "";
                        option1.Text         = "";
                        option2.Text         = "";
                        option3.Text         = "";
                        option4.Text         = "";
                        answer.SelectedIndex = 0;
                        quesBelong.IsChecked = false;
                    }
                    else
                    {
                        QuestionsBank quesBank = greDatabase.GetQuestion(Convert.ToInt32(quesId));
                        quesBank.Question = ques;
                        quesBank.Option1  = opt1;
                        quesBank.Option2  = opt2;
                        quesBank.Option3  = opt3;
                        quesBank.Option4  = opt4;
                        quesBank.Answer   = ans;
                        if (quesBelong.IsChecked == false)
                        {
                            quesBank.WordId = Convert.ToInt32(wordIdTextBox.Text);
                        }
                        else
                        {
                            Words word = (Words)((MainWindow)Application.Current.MainWindow).wordListView.SelectedValue;
                            wordIdTextBox.Text = word.WordId.ToString();
                            wordTextBox.Text   = word.Word;
                        }
                        greDatabase.UpdateQuestion(quesBank);
                        MessageBox.Show("Successfully updated to the question bank!", "QuestionBank", MessageBoxButton.OK, MessageBoxImage.Information);
                        questionId.Text               = "";
                        question.Text                 = "";
                        option1.Text                  = "";
                        option2.Text                  = "";
                        option3.Text                  = "";
                        option4.Text                  = "";
                        answer.SelectedIndex          = 0;
                        quesBelong.IsChecked          = false;
                        questionTabView.SelectedIndex = 1;
                        addQuestion.Content           = "Add To The Question Bank";
                        cancel.Visibility             = Visibility.Hidden;
                    }
                }
            }
        }