示例#1
0
        /// <summary>
        /// Adds a selected answer to the survey response model.
        /// </summary>
        /// <param name="answer">The answer to add.<param>
        public void AddAnswer(SurveyQuestionAnswerChoiceResponseModel answer)
        {
            // Check if a question response model has already been created for the question
            var existingQuestion = _response.Item.QuestionResponses.FirstOrDefault(r => r.QuestionID == answer.QuestionID);

            if (existingQuestion == null)
            {
                // If not yet created, create a new question response model
                existingQuestion = new SurveyQuestionResponseModel
                {
                    QuestionID = answer.QuestionID,
                };

                _response.Item.QuestionResponses.Add(existingQuestion);
            }

            var existingAnswer = existingQuestion.AnswerChoiceResponses.FirstOrDefault(a => a.AnswerChoiceID == answer.AnswerChoiceID);

            if (existingAnswer == null)
            {
                // Add the answer to the question response model
                existingQuestion.AnswerChoiceResponses.Add(answer);
            }
            else
            {
                // If the answer already exists, we should report this (not expected behavior)
                var properties = new Dictionary <string, string>
                {
                    { "QuestionID", answer.QuestionID.ToString() },
                    { "AnswerChoiceID", answer.AnswerChoiceID.ToString() },
                };

                DependencyService.Get <IMetricsManagerService>().TrackEvent("DuplicateAnswer", properties, null);
            }
        }
示例#2
0
        public static SurveyResponseModel GenerateRandomResponseForSurvey(Survey Survey)
        {
            var Addr = Generator.GenerateAddress();

            SurveyResponseModel Responses = new SurveyResponseModel()
            {
                StartTime   = DateTime.Now.AddMinutes(-7),
                EndTime     = DateTime.Now,
                GPSLocation = new PITCSurveyLib.GPSLocation()
                {
                    Lat = 47.6419587, Lon = -122.1327818, Accuracy = 0
                },
                NearestAddress = new PITCSurveyLib.Address()
                {
                    Street  = Addr.AddressLine,
                    City    = Addr.City,
                    State   = Addr.StateAbbreviation,
                    ZipCode = Addr.ZipCode
                },
                LocationNotes      = "",
                SurveyID           = 1,
                Survey_Version     = Survey.Version,
                ResponseIdentifier = Guid.NewGuid(),
            };

            foreach (var Question in Survey.SurveyQuestions)
            {
                var Response = new SurveyQuestionResponseModel()
                {
                    QuestionID = Question.ID
                };

                int AnswersToSelect = Question.Question.AllowMultipleAnswers ? Rnd.Next(1, Question.AnswerChoices.Count() / 4) : 1;

                for (int i = 0; i < AnswersToSelect; i++)
                {
                    SurveyAnswerChoice Choice = Question.AnswerChoices[i];

                    SurveyQuestionAnswerChoiceResponseModel Answer = new SurveyQuestionAnswerChoiceResponseModel()
                    {
                        QuestionID     = Question.Question.ID,
                        AnswerChoiceID = Choice.AnswerChoice.ID
                    };

                    switch (Choice.AnswerChoice.AdditionalAnswerDataFormat)
                    {
                    case PITCSurveyLib.AnswerFormat.Int:
                        Answer.AdditionalAnswerData = Ints().ToString();
                        break;

                    case PITCSurveyLib.AnswerFormat.Date:
                        Answer.AdditionalAnswerData = Dates().ToShortDateString();
                        break;

                    case PITCSurveyLib.AnswerFormat.String:
                        if (Question.Question.WellKnownQuestion == PITCSurveyLib.WellKnownQuestion.NameOrInitials)
                        {
                            Answer.AdditionalAnswerData = Names();
                        }
                        else
                        {
                            Answer.AdditionalAnswerData = Words();
                        }
                        break;

                    default:
                        break;
                    }

                    Response.AnswerChoiceResponses.Add(Answer);
                }

                Responses.QuestionResponses.Add(Response);
            }

            return(Responses);
        }