public void FillMissingSurveyInformation(Survey survey)
 {
     try
     {
         FillMissingCollectorDetails(survey);
         FillMissingResponseCounts(survey);
         FillMissingSurveyDetails(survey);
         FillMissingResponseDetails(survey);
         MatchResponsesToSurveyStructure(survey);
     }
     catch (Exception e)
     {
         throw new SurveyMonkeyException("Could not fill missing survey information", e);
     }
 }
 private void FillMissingSurveyDetails(Survey survey)
 {
     Survey surveyDetails = GetSurveyDetails(survey.SurveyId);
     survey.DateCreated = surveyDetails.DateCreated;
     survey.DateModified = surveyDetails.DateModified;
     survey.Language = surveyDetails.Language;
     survey.NumResponses = surveyDetails.NumResponses;
     survey.QuestionCount = surveyDetails.QuestionCount;
     survey.Nickname = surveyDetails.Nickname;
     survey.TitleText = surveyDetails.TitleText;
     survey.TitleEnabled = surveyDetails.TitleEnabled;
     survey.Pages = surveyDetails.Pages;
     survey.CustomVariables = surveyDetails.CustomVariables;
     survey.CustomVariableCount = surveyDetails.CustomVariableCount;
 }
Beispiel #3
0
 public Survey ToSurvey()
 {
     var survey = new Survey()
     {
         SurveyId = SurveyId,
         DateCreated = DateCreated,
         DateModified = DateModified,
         Nickname = Title,
         Language = LanguageId,
         QuestionCount = QuestionCount,
         NumResponses = NumResponses,
         AnalysisUrl = AnalysisUrl,
         PreviewUrl = PreviewUrl
     };
     return survey;
 }
        private void FillMissingResponseDetails(Survey survey)
        {
            IEnumerable<Response> responses = GetAllSurveyResponses(survey);

            //Need to initialise responses before adding to them
            foreach (var collector in survey.Collectors)
            {
                collector.Responses = new List<Response>();
            }
            
            Dictionary<long, Collector> collectorLookup = survey.Collectors.ToDictionary(c => c.CollectorId, c => c);
            foreach (var response in responses)
            {
                collectorLookup[response.Respondent.CollectorId].Responses.Add(response);
            }

            survey.Collectors = collectorLookup.Values.ToList();
        }
Beispiel #5
0
 public Survey ToSurvey()
 {
     var survey = new Survey()
     {
         SurveyId = SurveyId,
         DateCreated = DateCreated,
         DateModified = DateModified,
         TitleText = Title.Text,
         TitleEnabled = Title.Enabled,
         Language = LanguageId,
         QuestionCount = QuestionCount,
         NumResponses = NumResponses,
         Nickname = Nickname,
         Pages = Pages,
         CustomVariableCount = CustomVariableCount,
         CustomVariables = CustomVariables
     };
     return survey;
 }
        private IEnumerable<Response> GetAllSurveyResponses(Survey survey)
        {
            List<Respondent> respondents = GetRespondentList(survey.SurveyId);

            Dictionary<long, Response> responseLookup = respondents
                .Select(respondent => new Response
                {
                    Respondent = respondent,
                    RespondentId = respondent.RespondentId
                })
                .ToDictionary(r => r.RespondentId, r => r);

            List<long> respondentIds = respondents.Select(r => r.RespondentId).ToList();
            List<Response> responses = GetResponses(survey.SurveyId, respondentIds);

            foreach (var newResponse in responses.Where(newResponse => newResponse != null))
            {
                responseLookup[newResponse.RespondentId].Questions = newResponse.Questions;
            }

            IEnumerable<Response> result = responseLookup.Values.ToList();
            return result;
        }
 private void FillMissingCollectorDetails(Survey survey)
 {
     survey.Collectors = GetCollectorList(survey.SurveyId);
 }
 private void MatchResponsesToSurveyStructure(Survey survey)
 {
     foreach (var question in survey.Questions)
     {
         question.AnswersLookup = question.Answers.Where(a => a.AnswerId != 0).ToDictionary(a => a.AnswerId, a => a);
     }
     
     if (survey.CustomVariables != null)
     {
         survey.CustomVariablesLookup = survey.CustomVariables.Where(c => c.QuestionId != 0).ToDictionary(c => c.QuestionId, c => c);
     }
     
     Dictionary<long, Question> questionsLookup = survey.Questions.Where(q => q.QuestionId != 0).ToDictionary(q => q.QuestionId, q => q);
     
     foreach (var collector in survey.Collectors)
     {
         MatchCollectorsToSurveyStructure(questionsLookup, survey.CustomVariablesLookup, collector);
     }
 }
 private void FillMissingResponseCounts(Survey survey)
 {
     foreach (var collector in survey.Collectors)
     {
         Collector countDetails = GetResponseCounts(collector.CollectorId);
         collector.Completed = countDetails.Completed;
         collector.Started = countDetails.Started;
     }
 }
 private void FillMissingCollectorDetails(Survey survey)
 {
     survey.Collectors = GetCollectorList(survey.SurveyId);
 }