示例#1
0
        public IActionResult Index4()
        {
            var sessionId = TempData["SessionId"].ToString();

            var questionModel = _questions.GetAllByLevel(0);
            var q             = questionModel.Select(q => new QuestionListingModel
            {
                Id       = q.Id,
                Level    = q.Level,
                Order    = q.Order,
                Question = q.Question
            }).ToList();

            // load model for UI ... ALL ANSWERED questions
            var answerModel = _answers.GetAllBySurvey(sessionId);
            var a           = answerModel.Select(a => new SurveyListingModel
            {
                Id         = a.Id,
                SessionId  = a.SessionId,
                QMaster    = a.QMaster,
                Answer     = a.Answer,
                AnswerText = _answerOptions.GetAnswerText(a.QMaster.Key, a.Answer),
                Votes      = _answers.GetTotalVotes(a.QMaster.Id, a.QMaster.Key),
                Percentage = _answers.GetAnswerPercentage(_answers.GetTotalVotes(a.QMaster.Id, a.QMaster.Key),
                                                          _answers.GetTotalSessions())
            }).ToList();


            // first, get all questions/answers based on the current session
            //var surveySummary = _answers.GetAllBySurvey(sessionId);

            //var answerSummary = _answers.GetAllSurveyResults(sessionId);
            //// second, load up the SurveyAnswerListingModel ... loop through each question/answer combo and return stats
            //var a_s = answerSummary.Select(a => new SurveyAnswerListingModel
            //{
            //    Id = a.Id,
            //    Key = a.QMaster.Key,
            //    Val = a.AMaster.Val,
            //    AnswerText = _answerOptions.GetAnswerText(a.QMaster.Key, a.AMaster.Val),
            //    Votes = _answers.GetTotalVotes(a.QMaster.Id, a.QMaster.Key),
            //    Percentage = _answers.GetAnswerPercentage(_answers.GetTotalVotes(a.QMaster.Id, a.QMaster.Key),
            //                    _answers.GetTotalSessions())

            //}).ToList();

            //// third, compile data ...
            //var s = surveySummary.Select(a => new SurveySummaryModel
            //{
            //    QuestionId = a.QMaster.Id,
            //    AnswerKey = a.QMaster.Key,
            //    SessionAnswer = a.Answer,
            //    AnswerText = _answerOptions.GetAnswerText(a.QMaster.Key, a.Answer),
            //    AnswerStats = a_s
            //}).ToList();

            var model = new ResultListingModel
            {
                TotalSessions = _answers.GetTotalSessions(),
                Answers       = a
                                //Summary = s
            };

            TempData.Keep();
            return(View(model));
        }