/// <summary>
 /// Adds the specified question.
 /// </summary>
 /// <param name="question">The question.</param>
 public static void Add(Question question)
 {
     using (var context = new Entities())
     {
         context.Questions.Add(question);
         context.SaveChanges();
     }
 }
示例#2
0
        /// <summary>
        /// Generates the XML from singe question.
        /// </summary>
        /// <param name="question">The question.</param>
        /// <param name="numbering">The numbering.</param>
        /// <returns>Generated xml.</returns>
        public static XElement GenerateXml(Question question, AnswerNumbering numbering = AnswerNumbering.Numerical)
        {
            var questionRoot = new XElement(QuestionTag);
            questionRoot.SetAttributeValue(TypeAttribute, "multichoice");
            if (!string.IsNullOrEmpty(question.Name))
            {
                var name = new XElement(NameTag);
                name.Add(new XElement(TextTag, question.Name));
                questionRoot.Add(name);
            }

            var questionText = new XElement(QuestionTextTag);
            questionText.SetAttributeValue("format", "html");
            var textTag = new XElement(TextTag);
            textTag.Add(new XCData(question.Content));
            questionText.Add(textTag);
            questionRoot.Add(questionText);

            foreach (var answer in question.QuestionAnswers)
            {
                var answerTag = new XElement(AnswerTag);
                answerTag.SetAttributeValue("fraction", answer.Fraction);
                var answerText = new XElement(TextTag);
                answerText.Add(new XCData(answer.Content));
                answerTag.Add(answerText);
                questionRoot.Add(answerTag);
            }

            XElement answerNumbering;

            switch (numbering)
            {
                case AnswerNumbering.None:
                    answerNumbering = new XElement(AnswerNumberingTag, "none");
                    questionRoot.Add(answerNumbering);
                    break;
                case AnswerNumbering.Alphabetical:
                    answerNumbering = new XElement(AnswerNumberingTag, "abc");
                    questionRoot.Add(answerNumbering);
                    break;
                case AnswerNumbering.AlphabeticalCapitalized:
                    answerNumbering = new XElement(AnswerNumberingTag, "ABCD");
                    questionRoot.Add(answerNumbering);
                    break;
                case AnswerNumbering.Numerical:
                    answerNumbering = new XElement(AnswerNumberingTag, "123");
                    questionRoot.Add(answerNumbering);
                    break;
            }

            return questionRoot;
        }
示例#3
0
        /// <summary>
        /// Saves the changes.
        /// </summary>
        /// <param name="modifiedQuestion">The modified question.</param>
        public void SaveChanges(Question modifiedQuestion)
        {
            using (var context = new Entities())
            {
                var selectedQuestion = (from item in context.Questions.Include("QuestionCategory").Include("QuestionAnswers")
                                        where item.Id == modifiedQuestion.Id
                                        select item).FirstOrDefault();

                selectedQuestion.Content = modifiedQuestion.Content;
                selectedQuestion.ModificationDate = DateTime.Now;
                selectedQuestion.IsVisible = modifiedQuestion.IsVisible;
                for (int i = 0; i < selectedQuestion.QuestionAnswers.Count; ++i)
                {
                    selectedQuestion.QuestionAnswers.ElementAt(i).Content = modifiedQuestion.QuestionAnswers.ElementAt(i).Content;
                    selectedQuestion.QuestionAnswers.ElementAt(i).Fraction = modifiedQuestion.QuestionAnswers.ElementAt(i).Fraction;
                }

                context.SaveChanges();
            }
        }