Exemplo n.º 1
0
        private static TestQuestion ParseTestQuestion(JToken json)
        {
            var question = new TestQuestion();

            question.Id       = json["id"].Value <int>();
            question.HtmlText = json["content"].ToString();
            question.Points   = json["point"].Value <int>();

            if (json["image"] != null && json["image"].Type != JTokenType.Null)
            {
                question.ImageUrl = json["image"].ToString();
            }

            switch (json["type"].ToString())
            {
            case "quiz":
                question.Type = QuestionType.OneAnswer;
                break;

            case "multiquiz":
                question.Type = QuestionType.ManyAnswers;
                break;

            default:
                question.Type = QuestionType.Unknown;
                break;
            }

            foreach (var optionJson in json["options"])
            {
                var option = ParseQuestionOption(optionJson, out bool?isCorrect);
                option.Question = question;

                question.Options.Add(option);

                if (isCorrect.HasValue && isCorrect.Value)
                {
                    question.Answers.Add(option);
                }
            }

            return(question);
        }
Exemplo n.º 2
0
        public object Clone()
        {
            var question = new TestQuestion();

            question.Id       = Id;
            question.Points   = Points;
            question.HtmlText = HtmlText;
            question.ImageUrl = ImageUrl;
            question.Type     = Type;
            question.Options  = Options.Select(option => (QuestionOption)option.Clone()).ToList();
            question.Answers  = Answers.Select(answer => (QuestionOption)answer.Clone()).ToList();

            foreach (var option in Options)
            {
                option.Question = this;
            }

            foreach (var answer in Answers)
            {
                answer.Question = this;
            }

            return(question);
        }