Ejemplo n.º 1
0
 public static void AddQuestionWithAnswers(QuestionWithAnswers questionWithAnswers, long quizId)
 {
     DataAccessMachine.AddQuestionToDb(questionWithAnswers.QuestionText,quizId);
     foreach ( var answer in questionWithAnswers.Answers)
     {
         DataAccessMachine.AddAnswerToDb(answer);
     }
 }
Ejemplo n.º 2
0
        protected void FillInQuestionAndAnswers(QuestionWithAnswers questionWithAnswers)
        {
            Question.Text = questionWithAnswers.QuestionText;

            var answer1 = questionWithAnswers.Answers.ElementAt(0);
            Answer1.Text = answer1.answerText;
            Answer1.CommandArgument = answer1.ID.ToString();

            var answer2 = questionWithAnswers.Answers.ElementAt(1);
            Answer2.Text = answer2.answerText;
            Answer2.CommandArgument = answer2.ID.ToString(CultureInfo.InvariantCulture);

            var answer3 = questionWithAnswers.Answers.ElementAt(2);
            Answer3.Text = answer3.answerText;
            Answer3.CommandArgument = answer3.ID.ToString(CultureInfo.InvariantCulture);

            var answer4 = questionWithAnswers.Answers.ElementAt(3);
            Answer4.Text = answer4.answerText;
            Answer4.CommandArgument = answer4.ID.ToString(CultureInfo.InvariantCulture);
        }
Ejemplo n.º 3
0
 public static List<QuestionWithAnswers> GetQuestions(long quizId)
 {
     var tableAdapter = new QuestionTableAdapter();
     var dataTable = tableAdapter.GetQuestions(quizId);
     var questions = new List<QuestionWithAnswers>();
     foreach (var row in dataTable)
     {
         var question = new QuestionWithAnswers
         {
             Id = row.QuestionId,
             QuestionText = row.Text,
             QuizId = row.QuizId
         };
         questions.Add(question);
     }
     return questions;
 }
Ejemplo n.º 4
0
        public static QuestionWithAnswers GetNextQuestion(long quizId, long previousQuestionId)
        {
            var tableAdapter = new QuestionTableAdapter();
            var dataTable = tableAdapter.GetNextQuestion(previousQuestionId, quizId);
            foreach (var row in dataTable) {
                var questionWithAnswers = new QuestionWithAnswers
                {
                    Id = row.QuestionId,
                    QuestionText = row.Text,
                    QuizId = quizId
                };
                return questionWithAnswers;
            }
            return null;

            /*using (var connection = new SqlConnection(ConnectionString))
            {
                var questionWithAnswers = new QuestionWithAnswers();
                connection.Open();
                var questionCmd =
                    new SqlCommand("SELECT * FROM Question WHERE QuestionId > @QuestionId AND QuizId = @QuizId",
                        connection);
                questionCmd.Parameters.Add(@"QuestionId", SqlDbType.BigInt).Value = previousQuestionId;
                questionCmd.Parameters.Add(@"QuizId", SqlDbType.BigInt).Value = quizId;
                questionCmd.Prepare();
                var reader = questionCmd.ExecuteReader();
                while (reader.Read())
                {
                    questionWithAnswers.Id = (long) reader["QuestionId"];
                    questionWithAnswers.QuestionText = (string) reader["Text"];
                    questionWithAnswers.QuizId = (long) reader["QuizId"];
                    return questionWithAnswers;
                }
            }
            return null;*/
        }
Ejemplo n.º 5
0
 protected void SubmitQuestionWithAnswers(object sender, EventArgs e)
 {
     var questionWithAnswers = new QuestionWithAnswers
     {
         QuestionText = QuestionTextBox.Text,
         Answers = new List<Answer>
         {
             new Answer
             {
                 answerText = CorrectTextBox.Text,
                 isCorrect = true
             },
             new Answer
             {
                 answerText = WrongTextBox1.Text,
                 isCorrect = false
             },
             new Answer
             {
                 answerText = WrongTextBox2.Text,
                 isCorrect = false
             },
             new Answer
             {
                 answerText = WrongTextBox3.Text,
                 isCorrect = false
             }
         }
     };
     long quizId = long.Parse(Request.QueryString["quizId"]);
     GameMaster.AddQuestionWithAnswers(questionWithAnswers, quizId);
     Server.Transfer("EditQuizForm.aspx?quizId=" + quizId);
 }