Ejemplo n.º 1
0
        public SurveyResult Score(
            User user,
            string[] answers)
        {
            if (answers.Length != Questions.Count)
            {
                throw new ArgumentOutOfRangeException("answers", "Count of answers must equal the count of Questions in order to score the survey.");
            }

            // create a result structure
            var r = new SurveyResult
            {
                User         = user.Document.Id,
                Survey       = Document.Id,
                Title        = Content.Title,
                Taken        = DateTime.UtcNow,
                PointsEarned = Points,
                Answers      = new List <SurveyResultAnswer>(),
            };

            // score questions 1 by 1
            for (var i = 0; i < Questions.Count; i++)
            {
                var q = Questions[i];
                r.Answers.Add(new SurveyResultAnswer
                {
                    Question = q.Title,
                    Answer   = q.Freeform ? answers[i] : q.Answers[int.Parse(answers[i])].Title,
                });
            }

            return(r);
        }
Ejemplo n.º 2
0
        public SurveyResult Score(
            User user,
            string[] answers)
        {
            if (answers.Length != Questions.Count)
            {
                throw new ArgumentOutOfRangeException("answers", "Count of answers must equal the count of Questions in order to score the survey.");
            }

            // create a result structure
            var r = new SurveyResult
            {
                User = user.Document.Id,
                Survey = Document.Id,
                Title = Content.Title,
                Taken = DateTime.UtcNow,
                PointsEarned = Points,
                Answers = new List<SurveyResultAnswer>(),
            };

            // score questions 1 by 1
            for (var i = 0; i < Questions.Count; i++)
            {
                var q = Questions[i];
                r.Answers.Add(new SurveyResultAnswer
                {
                    Question = q.Title,
                    Answer = q.Freeform ? answers[i] : q.Answers[int.Parse(answers[i])].Title,
                });
            }

            return r;
        }