/// <summary> /// The process distractors. /// </summary> /// <param name="question"> /// The question. /// </param> /// <param name="convertedQuestion"> /// The converted question. /// </param> /// <param name="saveImage"> /// The save image. /// </param> /// <param name="subModuleItem"> /// The sub module item. /// </param> /// <param name="creator"> /// The creator. /// </param> /// <param name="distractorModel"> /// The distractor model. /// </param> private static void ProcessDistractors( EdugameQuestion question, Question convertedQuestion, Func <string, string, File> saveImage, SubModuleItem subModuleItem, User creator, DistractorModel distractorModel) { foreach (EdugameDistractor distractor in question.Distractors) { Distractor convertedDistractor = EdugameConverter.Convert(distractor, convertedQuestion); File distractorImage = saveImage(distractor.ImageName, distractor.Image); if (distractorImage != null) { convertedDistractor.Image = distractorImage; } if (convertedDistractor.CreatedBy == null) { convertedDistractor.CreatedBy = subModuleItem.Return(x => x.CreatedBy, creator); } if (convertedDistractor.ModifiedBy == null) { convertedDistractor.ModifiedBy = convertedDistractor.CreatedBy; } if (subModuleItem != null) { distractorModel.RegisterSave(convertedDistractor); } convertedQuestion.Distractors.Add(convertedDistractor); } }
/// <summary> /// Converts WebEx question to Edugame question. /// </summary> /// <param name="value">WebEx question.</param> /// <param name="questionTypes">List of question types DTO.</param> /// <returns>Edugame question.</returns> public static EdugameQuestion Convert(WebExQuestion value, List <QuestionType> questionTypes) { if (value == null) { return(null); } var result = new EdugameQuestion { Distractors = value.Answers.Select(Convert).ToList(), Feedback = new EdugameQuestionFeedback { Correct = string.Empty, Incorrect = string.Empty }, Instruction = string.Empty, Order = 0, Score = 0, Title = value.Title, Type = Convert(value.Type, questionTypes) }; //to be multiple at least 2 distractors should be set as IsCorrect if (value.Type == WebExQuestionType.MultipleChoice) { if (result.Distractors.Count(x => x.IsCorrect) <= 1) { result.Distractors.ForEach(x => x.IsCorrect = true); } } //in case of single choice only one should be true if (value.Type == WebExQuestionType.SingleChoice) { if (result.Distractors.Count(x => x.IsCorrect) == 0) { var distractor = result.Distractors.FirstOrDefault(); if (distractor != null) { distractor.IsCorrect = true; } } } return(result); }
/// <summary> /// The process custom questions. /// </summary> /// <param name="question"> /// The question. /// </param> /// <param name="dto"> /// The DTO. /// </param> /// <returns> /// The <see cref="QuestionFor"/>. /// </returns> private QuestionFor ProcessCustomQuestionType(Question question, EdugameQuestion dto) { switch (question.QuestionType.Id) { case (int)QuestionTypeEnum.TrueFalse: var qtf = new QuestionForTrueFalse { PageNumber = dto.PageNumber, IsMandatory = dto.IsMandatory ?? false, Question = question }; if (question.SubModuleItem != null) { this.QuestionForTrueFalseModel.RegisterSave(qtf); } return(qtf); case (int)QuestionTypeEnum.Rate: var qr = new QuestionForRate { AllowOther = dto.AllowOther, Restrictions = dto.Restrictions, PageNumber = dto.PageNumber, IsMandatory = dto.IsMandatory ?? false, Question = question }; if (question.SubModuleItem != null) { this.QuestionForRateModel.RegisterSave(qr); } return(qr); case (int)QuestionTypeEnum.OpenAnswerMultiLine: case (int)QuestionTypeEnum.OpenAnswerSingleLine: var qoa = new QuestionForOpenAnswer(); qoa.Restrictions = dto.Restrictions; qoa.PageNumber = dto.PageNumber; qoa.IsMandatory = dto.IsMandatory ?? false; qoa.Question = question; if (question.SubModuleItem != null) { this.QuestionForOpenAnswerModel.RegisterSave(qoa); } return(qoa); case (int)QuestionTypeEnum.RateScaleLikert: var ql = new QuestionForLikert { AllowOther = dto.AllowOther, PageNumber = dto.PageNumber, IsMandatory = dto.IsMandatory ?? false, Question = question }; if (question.SubModuleItem != null) { this.QuestionForLikertModel.RegisterSave(ql); } return(ql); case (int)QuestionTypeEnum.SingleMultipleChoiceImage: case (int)QuestionTypeEnum.SingleMultipleChoiceText: var qc = new QuestionForSingleMultipleChoice { AllowOther = dto.AllowOther, PageNumber = dto.PageNumber, IsMandatory = dto.IsMandatory ?? false, Restrictions = dto.Restrictions, Question = question }; if (question.SubModuleItem != null) { this.QuestionForSingleMultipleChoiceModel.RegisterSave(qc); } return(qc); case (int)QuestionTypeEnum.WeightedBucketRatio: var qw = new QuestionForWeightBucket { AllowOther = dto.AllowOther, PageNumber = dto.PageNumber, TotalWeightBucket = dto.TotalWeightBucket, WeightBucketType = dto.WeightBucketType, IsMandatory = dto.IsMandatory ?? false, Question = question }; if (question.SubModuleItem != null) { this.QuestionForWeightBucketModel.RegisterSave(qw); } return(qw); } return(null); }