Beispiel #1
0
        public static List <Question> GetAllQuestionsWithoutAnswers(DBConnection connection)
        {
            SqlCommand command = connection.GetCommand(QuestionTable.SQL_SELECT_ALL_QUESTIONS_NO_ANSWERS);

            using (SqlDataReader reader = command.ExecuteReader())
            {
                List <Question> questions = new List <Question>();

                while (reader.Read())
                {
                    questions.Add(QuestionTable.ReadQuestion(reader));
                }

                return(questions);
            }
        }
Beispiel #2
0
        public static Question GetQuestionById(DBConnection connection, int questionId)
        {
            SqlCommand command = connection.GetCommand(QuestionTable.SQL_SELECT_QUESTION_BY_ID);

            command.AddParameter("@questionId", SqlDbType.Int, questionId);

            try
            {
                Question question = null;

                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        if (question == null)
                        {
                            question = QuestionTable.ReadQuestion(reader);
                        }

                        QuestionAnswer answer = new QuestionAnswer(question.Id, reader.GetColumnValue <int>("index"), reader.GetColumnValue <string>("qa_text"), reader.GetColumnValue <bool>("correct"));
                        question.AddAnswer(answer);
                    }
                }

                if (question == null)
                {
                    throw new DatabaseException("Question does not exist");
                }

                return(question);
            }
            catch (Exception e)
            {
                throw new DatabaseException(e.Message);
            }
        }
Beispiel #3
0
 public static Question InsertQuestion(DBConnection connection, User creator, string text, string type, List <QuestionAnswer> answers)
 {
     return(QuestionTable.InsertQuestion(connection, creator.Id, text, type, answers));
 }
Beispiel #4
0
 public Question GetQuestion(DBConnection connection)
 {
     return(QuestionTable.GetQuestionById(connection, this.QuestionId));
 }