private void ApplySurveyResponse(Model.Survey survey, SurveyResponse surveyResponse) { // Select/Populate the answers on the survey object based on the response foreach (var answer in surveyResponse.Answers) { var question = survey.Questions.Find(q => q.SurveyQuestionID == answer.SurveyQuestionID); if (question != null) { switch (question.AnswerType) { case AnswerType.MultiSelect: case AnswerType.Select: { var option = question.PossibleAnswers.FirstOrDefault(a => a.AnswerText == answer.Answer); if (option != null) { option.IsSelected = true; } } break; case AnswerType.Text: { if (question.InputType == InputType.MultiText) { question.PossibleAnswers.Add(new SurveyAnswer() { SurveyQuestionID = answer.SurveyQuestionID, AnswerText = answer.Answer }); question.PossibleAnswers.Last().IsSelected = true; } else { question.Answer = answer.Answer; } } break; } } } // Set the raw Current Response survey.CurrentResponse = surveyResponse; // Set the audit info survey.CreateUserID = surveyResponse.CreateUserID; survey.CreateDate = surveyResponse.CreateDate; survey.CreateDateUtc = surveyResponse.CreateDateUtc; survey.ModifyUserID = surveyResponse.ModifyUserID; survey.ModifyDate = surveyResponse.ModifyDate; survey.ModifyDateUtc = surveyResponse.ModifyDateUtc; // Set the active page survey.Pages.First(p => p.SurveyPageID == surveyResponse.SelectedSurveyPageID).IsSelected = true; // Now, run the rulesets if (!string.IsNullOrEmpty(survey.RulesetCoreName)) { _ruleService.ExecuteRuleSet(new RulesetRequest() { Name = survey.RulesetCoreName, Survey = survey, EntityType = RulesetRequestEntityType.Survey }); } if (!string.IsNullOrEmpty(survey.RulesetValidationName)) { _ruleService.ExecuteRuleSet(new RulesetRequest() { Name = survey.RulesetCoreName, Survey = survey, EntityType = RulesetRequestEntityType.Survey }); } }