/// <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); } }
private void CreateDistractors( QuestionDTO dto, Question question, DistractorModel distractorModel, QuestionDTO result) { var distractors = new List <DistractorDTO>(); foreach (var distractorDTO in dto.distractors) { distractorDTO.questionId = question.Id; ValidationResult distractorValidationResult; if (this.IsValid(distractorDTO, out distractorValidationResult)) { Distractor distractor = null; bool savedSuccessfully = false; try { var isDistractorTransient = distractorDTO.distractorId == 0; distractor = isDistractorTransient ? null : distractorModel.GetOneById(distractorDTO.distractorId).Value; distractor = DistractorService.ConvertDto( distractorDTO, distractor, false, this.FileModel, this.QuestionModel, this.UserModel, this.SubModuleItemModel); distractorModel.RegisterSave(distractor, true); savedSuccessfully = true; } finally { if (distractor != null && savedSuccessfully && result != null) { distractors.Add(new DistractorDTO(distractor)); } } } } if (result != null) { result.distractors = distractors.ToArray(); } }