Пример #1
0
        //INFO: Return all questions in the database.
        public List <QuestionDO> GetQuestions(int id)
        {
            List <QuestionDO> questionDOs = new List <QuestionDO>();

            using (riverkeeperEntities RKEntities = new riverkeeperEntities())
            {
                List <Question> questions = (from q in RKEntities.Questions
                                             where q.SurveyId == id
                                             select q).ToList();
                foreach (var question in questions)
                {
                    if (question != null)
                    {
                        QuestionDO questionDO = new QuestionDO()
                        {
                            QuestionId      = question.QuestionId,
                            Type            = (short)question.Type,
                            Wording         = question.Wording,
                            PossibleAnswers = (String.IsNullOrEmpty(question.PossibleAnswers)) ? new string[0] : question.PossibleAnswers.Split(','),
                            SurveyId        = question.SurveyId
                        };
                        questionDOs.Add(questionDO);
                    }
                    if (question == null)
                    {
                        throw new Exception("No questions in DB");
                    }
                }
            }
            return(questionDOs);
        }
Пример #2
0
 public bool CreateQuestion(QuestionDO question)
 {
     if (question == null)
     {
         return(false);
     }
     return(questionDAO.CreateQuestion(question));
 }
Пример #3
0
        public static QuizDO QuizFixture_1()
        {
            var quiz = new QuizDO();

            quiz.AnswerTime = 3000;

            var questionLabel = new Label {
                Text = "What is the highest mountain of the world?"
            };
            var questionImage = new Image {
                ImagePath = "cdn://dksjdksjkd.com/image.png"
            };
            var questionContent = new ContentDO();

            questionContent.AddControl(questionLabel);
            questionContent.AddControl(questionImage);

            var question = new QuestionDO();

            question.Content = questionContent;

            var quizItem = new ItemDO();

            quizItem.SetQuestion(question);

            for (int i = 0; i < 4; ++i)
            {
                var answerLabel = new Label {
                    Text = "Everest"
                };
                var answerImage = new Image {
                    ImagePath = "cdn://dkhfjdkl.io/everest.png"
                };
                var answerContent = new ContentDO();
                answerContent.AddControl(answerLabel);
                answerContent.AddControl(answerImage);

                var answer = new AnswerDO();
                answer.Content = answerContent;

                quizItem.AddPossibleAnswer(answer);
            }

            quizItem.SetCorrectAnswer(new SingleChoiceAnswer {
                Value = 1
            });

            quiz.AddQuizItem(quizItem);

            return(quiz);
        }
Пример #4
0
        //INFO: Adds a question to the database.
        public bool CreateQuestion(QuestionDO questionDO)
        {
            using (riverkeeperEntities RKEntities = new riverkeeperEntities())
            {
                Question questiondb = new Question();

                questiondb.SurveyId        = questionDO.SurveyId;
                questiondb.Wording         = questionDO.Wording;
                questiondb.Type            = (ResponseFormat)questionDO.Type;
                questiondb.PossibleAnswers = String.Join(",", questionDO.PossibleAnswers);
                RKEntities.Questions.Add(questiondb);


                int dbResult = 0;

                try
                {
                    dbResult = RKEntities.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Debug.WriteLine("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }

                if (dbResult != 1)
                {
                    return(false);
                }

                return(true);
            }
        }
Пример #5
0
        //INFO: Retrieves the question with the given id
        public QuestionDO GetQuestionById(int id)
        {
            QuestionDO questionDO = new QuestionDO();

            using (riverkeeperEntities RKEntities = new riverkeeperEntities())
            {
                List <Question> questions = (from q in RKEntities.Questions where q.QuestionId == id
                                             select q).ToList();
                Question question = questions.ElementAt(0);

                if (question != null)
                {
                    questionDO.QuestionId      = question.QuestionId;
                    questionDO.Type            = (short)question.Type;
                    questionDO.Wording         = question.Wording;
                    questionDO.PossibleAnswers = question.PossibleAnswers.Split(',');
                }
                else
                {
                    throw new Exception("No questions with that ID in DB");
                }
            }
            return(questionDO);
        }
Пример #6
0
 public bool Post(QuestionDO question)
 {
     return(questionTask.CreateQuestion(question));
 }