Esempio n. 1
0
        public SurveyModel GetAllQuestion(int id)
        {
            var result = new SurveyModel();

            var resultQ = new List <QuestionModel>();

            using (_SurveyDb = new surveyEF())
            {
                var s         = _SurveyDb.sps_QAforSurvey(id).ToList <sps_QAforSurvey_Result>();
                var questions = s.Select(d => d.QuestionId).Distinct();
                foreach (var q in questions)
                {
                    var individualQ = (from obj in s
                                       where obj.QuestionId == q
                                       select new QuestionModel
                    {
                        QuestionId = q,
                        Text = obj.Text,
                        SurveyId = obj.SurveyId,
                        AnswerChoice = 0,
                        Answers = new List <AnswerModel>()
                    }).FirstOrDefault();

                    var ansInModel = (from obj in s
                                      where obj.QuestionId == q
                                      select new AnswerModel
                    {
                        AnswerId = obj.AnswerId,
                        Text = obj.Text1,
                        QuestionId = q,
                        Numbers = 0,
                        Checked = false,
                    }).ToList <AnswerModel>();

                    individualQ.Answers.AddRange(ansInModel);
                    resultQ.Add(individualQ);
                }
            }
            result.Questions = new List <QuestionModel>();
            result.Questions.AddRange(resultQ);
            result.SurveyId = 1;
            return(result);
        }