Exemplo n.º 1
0
 public void Save(MultipleDragAndDrop2 question)
 {
     if (question.Id == 0)
     {
         MultipleDragAndDrop2Repository.Create(question);
     }
     else
     {
         MultipleDragAndDrop2Repository.Update(question);
     }
 }
        public void Create(MultipleDragAndDrop2 question)
        {
            var questionXml = new MultipleDragAndDrop2_QuestionXmlModel()
            {
                Answers = question.AnswersList.Select(x => new MultipleDragAndDrop2_AnswerXmlModel()
                {
                    Id   = x.id,
                    Text = x.text,
                    DisplayAnswersVertically = x.DisplayAnswersVertically
                }).ToArray()
            };
            var questionXmlSerialized = Serializer.Serialize(questionXml);

            if (this.connection == null)
            {
                this.connection = new ConnectionProvider();
            }

            var questionId = new ObjectParameter("Questionid", typeof(int));

            this.connection.Db.Items_Insert(question.QuestionTypeId, question.QuestionText, question.Notes, questionXmlSerialized, questionId);

            question.Id = (int)questionId.Value;

            foreach (var target in question.Targets)
            {
                var targetXml = new MultipleDragAndDrop2_TargetXmlModel
                {
                    Id      = target.id,
                    Text    = target.text,
                    Answers = target.Answers.Select(x => new MultipleDragAndDrop2_TargetAnswerXmlModel()
                    {
                        AnswerId   = x.AnswerId,
                        AnswerText = x.AnswerText
                    }).ToArray(),
                };

                var targetXmlSerialized = Serializer.Serialize(targetXml);
                this.connection.Db.Answers_Insert(question.Id, "", null, 0, 0, "", targetXmlSerialized);
            }

            this.connection.Db.SaveChanges();
        }
Exemplo n.º 3
0
        public Question Get(int id)
        {
            var question = QuestionRepository.Get(id);

            if (question != null)
            {
                if (question.QuestionTypeId == 10)  // MovePointsInAChart
                {
                    var mpic    = new MovePointsInAChart(question);
                    var details = Serializer.Deserialize <MovePointsInAChart_QuestionXmlModel>(mpic.ExtendedDetails);
                    mpic.Domain     = details.Domain;
                    mpic.MinorScale = details.MinorScale;
                    mpic.MajorScale = details.MajorScale;
                    mpic.chartType  = details.chartType;

                    foreach (var answer in mpic.Answers)
                    {
                        var answerDetails = Serializer.Deserialize <MovePointsInAChart_SpotXmlModel>(answer.ExendedDetails);
                        if (answerDetails.SpotType == "center")
                        {
                            mpic.CenterSpot = new SpotContent
                            {
                                X = answerDetails.X,
                                Y = answerDetails.Y
                            };
                        }
                        else
                        {
                            mpic.MinMaxSpot = new SpotContent
                            {
                                X = answerDetails.X,
                                Y = answerDetails.Y
                            };
                        }
                    }
                    return(mpic);
                }
                else if (question.QuestionTypeId == 20)  // MovePointsInALine
                {
                    var mpil    = new MovePointsInALine(question);
                    var details = Serializer.Deserialize <MovePointsInALine_QuestionXmlModel>(mpil.ExtendedDetails);
                    mpil.MinValue   = details.MinValue;
                    mpil.MaxValue   = details.MaxValue;
                    mpil.MinorScale = details.MinorScale;
                    mpil.MajorScale = details.MajorScale;

                    var intervalsBuffer = new List <MovePointsInALine_Interval>();
                    foreach (var answer in mpil.Answers)
                    {
                        var answerDetails = Serializer.Deserialize <MovePointsInALine_IntervalXmlModel>(answer.ExendedDetails);
                        intervalsBuffer.Add(new MovePointsInALine_Interval
                        {
                            id           = answerDetails.Id,
                            minValue     = answerDetails.MinValue,
                            maxValue     = answerDetails.MaxValue,
                            minValueType = answerDetails.MinValueType,
                            maxValueType = answerDetails.MaxValueType,
                            shapeType    = answerDetails.ShapeType,
                            value        = answerDetails.Value,
                            label        = answerDetails.Label
                        });
                    }
                    mpil.Intervals = intervalsBuffer.ToArray();
                    return(mpil);
                }
                else if (question.QuestionTypeId == 30)  // SelectableChart
                {
                    var sc = new SelectableChart(question);

                    var columnsBuffer = new List <SelectableChart_Column>();
                    foreach (var answer in sc.Answers)
                    {
                        var answerDetails = Serializer.Deserialize <SelectableChart_ColumnXmlModel>(answer.ExendedDetails);
                        columnsBuffer.Add(new SelectableChart_Column
                        {
                            id       = answerDetails.Id,
                            label    = answerDetails.Label,
                            selected = answerDetails.Selected,
                            value    = answerDetails.Value
                        });
                    }
                    sc.Columns = columnsBuffer.ToArray();
                    return(sc);
                }
                else if (question.QuestionTypeId == 40)  // DragAndDrop
                {
                    var mdd = new MultipleDragAndDrop(question);

                    var details = Serializer.Deserialize <MultipleDragAndDrop_QuestionXmlModel>(mdd.ExtendedDetails);
                    mdd.AnswersList = details.Answers.Select(x => new MultipleDragAndDrop_Answer()
                    {
                        id   = x.Id,
                        text = x.Text,
                        DisplayAnswersVertically = x.DisplayAnswersVertically
                    }).ToArray();

                    var targetsBuffer = new List <MultipleDragAndDrop_Target>();
                    foreach (var answer in mdd.Answers)
                    {
                        var answerDetails = Serializer.Deserialize <MultipleDragAndDrop_TargetXmlModel>(answer.ExendedDetails);
                        targetsBuffer.Add(new MultipleDragAndDrop_Target
                        {
                            id         = answerDetails.Id,
                            text       = answerDetails.Text,
                            answerId   = answerDetails.AnswerId,
                            answerText = answerDetails.AnswerText
                        });
                    }
                    mdd.Targets = targetsBuffer.ToArray();
                    return(mdd);
                }
                else if (question.QuestionTypeId == 50)  // Drag And order
                {
                    var dao = new DragAndOrder(question);

                    var optionsBuffer = new List <DragAndOrder_Option>();
                    foreach (var answer in dao.Answers)
                    {
                        var answerDetails = Serializer.Deserialize <DragAndOrder_OptionXmlModel>(answer.ExendedDetails);
                        optionsBuffer.Add(new DragAndOrder_Option
                        {
                            id    = answerDetails.Id,
                            text  = answerDetails.Text,
                            worth = answerDetails.Worth
                        });
                    }
                    dao.Options = optionsBuffer.ToArray();
                    return(dao);
                }
                else if (question.QuestionTypeId == 42)  // MultipleDragAndDropImage
                {
                    var mddi = new MultipleDragAndDropImage(question);

                    var AnswersList = new List <MultipleDragAndDropImage_Answer>();
                    foreach (var answer in mddi.Answers)
                    {
                        AnswersList.Add(new MultipleDragAndDropImage_Answer
                        {
                            imgName   = answer.Txt,
                            imgData   = null,
                            imgURL    = answer.ExendedDetails,
                            isCorrect = answer.AnsVal,
                        });
                    }
                    mddi.AnswersList = AnswersList.ToArray();
                    return(mddi);
                }
                else if (question.QuestionTypeId == 44)  // MultipleDragAndDropJustification
                {
                    var mdd = new MultipleDragAndDropJustification(question);

                    // method and justification questions
                    var details = Serializer.Deserialize <MultipleDragAndDrop_JustificationQuestionXmlModel>(mdd.ExtendedDetails);
                    mdd.AnswersList = details.Answers.Select(x => new MultipleDragAndDrop_Answer()
                    {
                        id   = x.Id,
                        text = x.Text,
                    }).ToArray();

                    mdd.JustificationAnswersList = details.JustificationAnswers.Select(x => new MultipleDragAndDrop_JustificationAnswer()
                    {
                        id   = x.Id,
                        text = x.Text,
                    }).ToArray();

                    // method and justification  responses
                    var targetsBuffer  = new List <MultipleDragAndDrop_Target>();
                    var targetsBufferj = new List <MultipleDragAndDrop_JustificationTarget>();

                    foreach (var answer in mdd.Answers)
                    {
                        if (answer.ExendedDetails.IndexOf("MultipleDragAndDrop_TargetXmlModel") >= 0)
                        {
                            //method responses
                            var answerDetails = Serializer.Deserialize <MultipleDragAndDrop_TargetXmlModel>(answer.ExendedDetails);
                            targetsBuffer.Add(new MultipleDragAndDrop_Target
                            {
                                id         = answerDetails.Id,
                                text       = answerDetails.Text,
                                answerId   = answerDetails.AnswerId,
                                answerText = answerDetails.AnswerText
                            });
                        }
                        else if (answer.ExendedDetails.IndexOf("MultipleDragAndDrop_JustificationTargetXmlModel") >= 0)
                        {
                            //justification responses
                            var answerDetails = Serializer.Deserialize <MultipleDragAndDrop_JustificationTargetXmlModel>(answer.ExendedDetails);
                            targetsBufferj.Add(new MultipleDragAndDrop_JustificationTarget
                            {
                                id         = answerDetails.Id,
                                text       = answerDetails.Text,
                                answerId   = answerDetails.AnswerId,
                                answerText = answerDetails.AnswerText
                            });
                        }
                    }

                    mdd.Targets = targetsBuffer.ToArray();
                    mdd.JustificationTargets = targetsBufferj.ToArray();

                    return(mdd);
                }
                else if (question.QuestionTypeId == 12)  // DrawLinesInAChart
                {
                    var dlc = new DrawLinesInAChart(question);

                    // chart details
                    var chartDetails = Serializer.Deserialize <DrawLinesInAChart_QuestionXmlModel>(dlc.ExtendedDetails);
                    dlc.Domain     = chartDetails.Domain;
                    dlc.MajorScale = chartDetails.MajorScale;
                    dlc.MinorScale = chartDetails.MinorScale;

                    // line details
                    var AnswersList = new List <DrawLinesInAChartAnswer>();
                    foreach (var answer in dlc.Answers)
                    {
                        var answerDetails = Serializer.Deserialize <DrawLinesInAChart_AnswerXmlModel>(answer.ExendedDetails);
                        AnswersList.Add(new DrawLinesInAChartAnswer
                        {
                            axisValue = answerDetails.axisValue,
                            axisType  = answerDetails.axisType,
                        });
                    }
                    dlc.AnswersList = AnswersList.ToArray();

                    return(dlc);
                }
                else if (question.QuestionTypeId == 46)  // MultipleDragAndDropExpression
                {
                    var mdde = new MultipleDragAndDropExpression(question);

                    var details = Serializer.Deserialize <MultipleDragAndDropExpression_QuestionXmlModel>(mdde.ExtendedDetails);
                    mdde.AnswersList = details.Answers.Select(x => new MultipleDragAndDropExpression_Answer()
                    {
                        id   = x.Id,
                        text = x.Text,
                    }).ToArray();

                    var targetsBuffer = new List <MultipleDragAndDropExpression_Target>();
                    foreach (var answer in mdde.Answers)
                    {
                        var answerDetails = Serializer.Deserialize <MultipleDragAndDropExpression_TargetXmlModel>(answer.ExendedDetails);
                        targetsBuffer.Add(new MultipleDragAndDropExpression_Target
                        {
                            id                = answerDetails.Id,
                            text              = answerDetails.Text,
                            answerId          = answerDetails.AnswerId,
                            answerText        = answerDetails.AnswerText,
                            shape             = answerDetails.Shape,
                            container         = answerDetails.Container,
                            containerLabel    = answerDetails.ContainerLabel,
                            containerBorder   = answerDetails.ContainerBorder,
                            containerPosition = answerDetails.ContainerPosition
                        });
                    }
                    mdde.Targets = targetsBuffer.ToArray();
                    return(mdde);
                }
                else if (question.QuestionTypeId == 48)  // MultipleDragAndDrop
                {
                    var mdd = new MultipleDragAndDrop2(question);

                    // get the options
                    var details = Serializer.Deserialize <MultipleDragAndDrop2_QuestionXmlModel>(mdd.ExtendedDetails);
                    mdd.AnswersList = details.Answers.Select(x => new MultipleDragAndDrop2_Answer()
                    {
                        id   = x.Id,
                        text = x.Text,
                        DisplayAnswersVertically = x.DisplayAnswersVertically
                    }).ToArray();

                    var targetsBuffer = new List <MultipleDragAndDrop2_Target>();

                    // get the answers
                    foreach (var answer in mdd.Answers)
                    {
                        var answerDetails = Serializer.Deserialize <MultipleDragAndDrop2_TargetXmlModel>(answer.ExendedDetails);
                        targetsBuffer.Add(new MultipleDragAndDrop2_Target
                        {
                            id   = answerDetails.Id,
                            text = answerDetails.Text,
                        });
                        // add the possible options to the answer
                        for (int i = 0; i < targetsBuffer.Count; i++)
                        {
                            if (targetsBuffer[i].id == answerDetails.Id)
                            {
                                targetsBuffer[i].Answers = answerDetails.Answers.Select(x => new MultipleDragAndDrop2_TargetAnswer()
                                {
                                    AnswerId   = x.AnswerId,
                                    AnswerText = x.AnswerText
                                }).ToArray();
                            }
                        }
                    }

                    mdd.Targets = targetsBuffer.ToArray();
                    return(mdd);
                } // else if = 48  (Multiple Drag and Drop)
            }
            return(question);
        } // end Get