示例#1
0
        /// <summary>
        /// 某个polling所有question正确人数和参与人数
        /// </summary>
        /// <param name="polling"></param>
        /// <returns>question列表,每个question一行</returns>
        private List <PollingResultCustomView> PollingResultPerson(PollingView polling)
        {
            //var polling = Repository.Entities.FirstOrDefault(a => a.Id == pollingId);
            var pollingResultPersons = new List <PollingResultCustomView>();

            //var pollingAnswers = _pollingResultService.GetList(polling.Id);
            var pollingAnswers = _pollingResultService.GetBatchResultsByPollingId(polling.Id, 0, null, null);
            var pollingResult  = PollingResult(polling.Id, pollingAnswers, polling);

            // 循环得到每个question的答题情况
            foreach (var question in polling.PollingQuestions)
            {
                var pollingResultPerson = new PollingResultCustomView();
                int person        = 0;
                int answerPersons = 0;
                foreach (var questionresult in pollingResult)
                {
                    if (questionresult.CustomStatus.Equals("正确") && questionresult.QuestionId == question.Id)
                    {
                        person        += 1;
                        answerPersons += 1;
                    }
                    if (questionresult.CustomStatus.Equals("错误") && questionresult.QuestionId == question.Id)
                    {
                        answerPersons += 1;
                    }
                }
                pollingResultPerson.QuestionId    = question.Id;
                pollingResultPerson.RightPersons  = person;
                pollingResultPerson.answerPersons = answerPersons;
                pollingResultPersons.Add(pollingResultPerson);
            }

            return(pollingResultPersons);
        }
示例#2
0
        //答题正确人数
        public List <PollingResultCustomView> PollingResultPerson(int pollingId)
        {
            var polling = Repository.Entities.FirstOrDefault(a => a.Id == pollingId);
            var pollingResultPersons = new List <PollingResultCustomView>();

            var pollingAnswers = _pollingResultService.Repository.Entities.Where(a => a.PollingId == pollingId).Where(x => x.QuestionId != null).ToList();

            pollingAnswers.GroupBy(x => x.QuestionId).ToList().ForEach(y =>
            {
                var pollingResultPerson = new PollingResultCustomView();
                int person        = 0;
                int answerPersons = 0;
                foreach (var questionresult in PollingResult(pollingId))
                {
                    if (questionresult.CustomStatus.Equals("正确") && questionresult.QuestionId == y.Key)
                    {
                        person        += 1;
                        answerPersons += 1;
                    }
                    if (questionresult.CustomStatus.Equals("错误") && questionresult.QuestionId == y.Key)
                    {
                        answerPersons += 1;
                    }
                }
                pollingResultPerson.QuestionId    = y.Key;
                pollingResultPerson.RightPersons  = person;
                pollingResultPerson.answerPersons = answerPersons;
                pollingResultPersons.Add(pollingResultPerson);
            });

            return(pollingResultPersons);
        }
示例#3
0
        /// <summary>
        /// 将PollingResultList转换成每个question一条答案的方式,比如多选的多条Result转成1条(ABC)
        /// </summary>
        /// <param name="pollingID"></param>
        /// <param name="_pollingEntity"></param>
        /// <returns></returns>
        public List <PollingResultCustomView> PollingResult(int pollingId, IList <PollingResultEntity> pollingResultEntity, PollingView pollingView)
        {
            var pollingCustomView = new PollingCustomView {
                PollingId = pollingId
            };

            //var pollingView = GetPollingView(pollingId);

            foreach (var question in pollingView.PollingQuestions)
            {
                var pollingOptions = question.PollingOptionEntities.Where(a => (a.IsDeleted != true)).ToList();
                int i = 0;
                foreach (var option in pollingOptions)
                {
                    option.OptionIndex = i.ToString();//toABCD(i);
                    i++;
                }
            }

            // 开始处理答案
            var pollingAnswers = pollingResultEntity;

            // 同一个人对同一个question的答案(多选),需要汇总到一个里。

            //var empDetails = WeChatCommonService.lstUserWithDeptTag;

            var grouped = pollingAnswers.GroupBy(a => new { a.UserId, a.QuestionId });

            foreach (var g in grouped)
            {
                var question = pollingView.PollingQuestions.FirstOrDefault(a => a.Id == g.Key.QuestionId);
                if (question == null || question.Type == 99)
                {
                    continue;
                }

                //var emp = empDetails.SingleOrDefault(a => a.userid.Equals(g.Key.UserId, StringComparison.InvariantCultureIgnoreCase));
                var newAnswerResult = new PollingResultCustomView()
                {
                    QuestionId    = question.Id,
                    QuestionTitle = question.Title,
                    UserId        = g.Key.UserId,

                    //UserName = (emp != null ? emp.name : ""),
                    //UserDeptLv1 = (emp != null ? emp.deptLvs[2] : ""),
                    //UserDeptLv2 = (emp != null ? emp.deptLvs[3] : ""),
                    //UserDeptLv3 = (emp != null ? emp.deptLvs[4] : ""),
                };
                pollingCustomView.Results.Add(newAnswerResult);
                foreach (var v in g.ToList())
                {
                    var option = question.PollingOptionEntities.FirstOrDefault(a => a.Id == v.Answer && (a.IsDeleted != true));
                    if (option == null)
                    {
                        continue;
                    }
                    int optionIndex = int.Parse(option.OptionIndex);
                    //var answer = newAnswerResult.Answers[optionIndex];

                    newAnswerResult.AnswerTime = v.CreatedDate.GetValueOrDefault();

                    newAnswerResult.Answers[optionIndex].AnswerId   = v.Answer;
                    newAnswerResult.Answers[optionIndex].AnswerText = v.AnswerText;
                    var answered = newAnswerResult.Answers.Aggregate("", (current, answer) => current + (answer.AnswerId == 0 ? "N" : "Y"));

                    newAnswerResult.CustomAnswer = ConvertYNToABCStatic(answered, 10);
                    var questionstr = pollingView.PollingQuestions.FirstOrDefault(a => a.Id == newAnswerResult.QuestionId);
                    if (questionstr != null)
                    {
                        newAnswerResult.RightAnswers = questionstr.RightAnswers;
                    }
                    if (newAnswerResult.CustomAnswer == newAnswerResult.RightAnswers)
                    {
                        newAnswerResult.CustomStatus = "正确"; // : "错误";
                        newAnswerResult.IsRight      = true;
                    }
                    else
                    {
                        newAnswerResult.CustomStatus = "错误";
                        newAnswerResult.IsRight      = false;
                    }
                    //newAnswerResult.CustomStatus = newAnswerResult.CustomAnswer == newAnswerResult.RightAnswers ? "正确" : "错误";
                }
            }

            return(pollingCustomView.Results);
        }
示例#4
0
        //答题列表
        public List <PollingResultCustomView> PollingResult(int pollingId)
        {
            // 1. 取出polling,创建每个question和answer的列表
            var polling = Repository.Entities.FirstOrDefault(a => a.Id == pollingId && (a.IsDeleted == null || a.IsDeleted == false));

            if (polling == null)
            {
                throw new Exception("Polling为空!");
            }

            var pollingCustomView = new PollingCustomView {
                PollingId = pollingId
            };


            foreach (var question in polling.PollingQuestions)
            {
                var pollingQuestions = question.PollingOptionEntities.Where(a => (a.IsDeleted == null || a.IsDeleted == false));
                for (int i = 0; i < pollingQuestions.Count(); i++)
                {
                    var option = question.PollingOptionEntities.ElementAt(i);
                    option.OptionIndex = i.ToString();//toABCD(i);
                }
            }

            // 开始处理答案
            var pollingAnswers = _pollingResultService.Repository.Entities.Where(a => a.PollingId == pollingId && (a.IsDeleted == null || a.IsDeleted == false));

            // 同一个人对同一个question的答案(多选),需要汇总到一个里。

            foreach (var pollingAnswer in pollingAnswers)
            {
                var question = polling.PollingQuestions.FirstOrDefault(a => a.Id == pollingAnswer.QuestionId);
                if (question != null && question.Type == 99)
                {
                    continue;
                }

                // 如果是多选题的话,需要看是否已经有过,有过的话就合并答案
                //var newAnswerResult = pollingCustomView.Results.FirstOrDefault(a => a.QuestionId == question.Id && a.UserId == pollingAnswer.UserId);
                var newAnswerResult = pollingCustomView.Results.FirstOrDefault(a => a.QuestionId == question.Id && a.UserId.Equals(pollingAnswer.UserId, StringComparison.InvariantCultureIgnoreCase));
                var empDetails      = WeChatCommonService.lstUserWithDeptTag;
                if (newAnswerResult == null)
                {
                    var emp = empDetails.SingleOrDefault(a => a.userid.Equals(pollingAnswer.UserId, StringComparison.InvariantCultureIgnoreCase));

                    if (question != null)
                    {
                        newAnswerResult = new PollingResultCustomView()
                        {
                            QuestionId    = question.Id,
                            QuestionTitle = question.Title,
                            UserId        = pollingAnswer.UserId,

                            UserName    = (emp != null ? emp.name : ""),
                            UserDeptLv1 = (emp != null ? emp.deptLvs[2] : ""),
                            UserDeptLv2 = (emp != null ? emp.deptLvs[3] : ""),
                            UserDeptLv3 = (emp != null ? emp.deptLvs[4] : ""),
                            AnswerTime  = pollingAnswer.CreatedDate.GetValueOrDefault()
                        }
                    }
                    ;
                    pollingCustomView.Results.Add(newAnswerResult);
                }

                if (question != null)
                {
                    var option = question.PollingOptionEntities.FirstOrDefault(a => a.Id == pollingAnswer.Answer && (a.IsDeleted == null || a.IsDeleted == false));
                    if (option == null)
                    {
                        continue;
                    }
                    int optionIndex = int.Parse(option.OptionIndex);
                    var answer      = newAnswerResult.Answers[optionIndex];

                    newAnswerResult.Answers[optionIndex].AnswerId   = pollingAnswer.Answer;
                    newAnswerResult.Answers[optionIndex].AnswerText = pollingAnswer.AnswerText;
                }
            }

            foreach (var questionresult in pollingCustomView.Results)
            {
                var answered = questionresult.Answers.Aggregate("", (current, answer) => current + (answer.AnswerId == 0 ? "N" : "Y"));

                questionresult.CustomAnswer = ConvertYNToABCStatic(answered, 10);
                var questionstr = polling.PollingQuestions.FirstOrDefault(a => a.Id == questionresult.QuestionId);
                if (questionstr != null)
                {
                    questionresult.RightAnswers = questionstr.RightAnswers;
                }
                questionresult.CustomStatus = questionresult.CustomAnswer == questionresult.RightAnswers ? "正确" : "错误";
            }
            return(pollingCustomView.Results);
        }
示例#5
0
        public ActionResult GetUserAnswers(int pollingId)
        {
            // 1. 取出polling,创建每个question和answer的列表
            var polling = _pollingService.Repository.Entities.FirstOrDefault(a => a.Id == pollingId && (a.IsDeleted != true));

            if (polling == null)
            {
                throw new Exception("Polling丢了!");
            }

            PollingCustomView pollingCustomView = new PollingCustomView();

            pollingCustomView.PollingId   = pollingId;
            pollingCustomView.PollingName = polling.Name;

            // 把option转成ABCD
            foreach (var question in polling.PollingQuestions)
            {
                var pollingQuestions = question.PollingOptionView.Where(a => (a.IsDeleted == null || a.IsDeleted == false));
                for (int i = 0; i < pollingQuestions.Count(); i++)
                {
                    var option = pollingQuestions.ElementAt(i);
                    option.OptionIndex = i.ToString();//toABCD(i);
                }
            }

            // 在处理答案之前,先把用户和部门关系搞出来
            var employees = WeChatCommonService.lstUserWithDeptTag;


            // 开始处理答案
            var pollingAnswers = _pollingResultService.Repository.Entities.Where(a => a.PollingId == pollingId && (a.IsDeleted != true));

            // 同一个人对同一个question的答案(多选),需要汇总到一个里。

            foreach (var pollingAnswer in pollingAnswers)
            {
                var question = polling.PollingQuestions.FirstOrDefault(a => a.Id == pollingAnswer.QuestionId);
                if (question.Type == 99)
                {
                    continue;
                }

                // 如果是多选题的话,需要看是否已经有过,有过的话就合并答案
                var newAnswerResult = pollingCustomView.Results.FirstOrDefault(a => a.QuestionId == question.Id && a.UserId == pollingAnswer.UserId);
                if (newAnswerResult == null)
                {
                    var emp = employees.FirstOrDefault(a => a.userid == pollingAnswer.UserId);
                    newAnswerResult = new PollingResultCustomView()
                    {
                        QuestionId    = question.Id,
                        QuestionTitle = question.Title,
                        UserId        = pollingAnswer.UserId,
                        UserName      = (emp == null ? "NA" : emp.name),
                        UserDeptLv1   = (emp == null ? "NA" : emp.deptLvs[2]),
                        UserDeptLv2   = (emp == null ? "NA" : emp.deptLvs[3]),
                        UserDeptLv3   = (emp == null ? "NA" : emp.deptLvs[4]),
                        AnswerTime    = pollingAnswer.CreatedDate.Value
                    };
                    pollingCustomView.Results.Add(newAnswerResult);
                }

                var option = question.PollingOptionView.FirstOrDefault(a => a.Id == pollingAnswer.Answer && (a.IsDeleted != true));
                if (option == null)
                {
                    continue;
                }
                int optionIndex = int.Parse(option.OptionIndex);
                var answer      = newAnswerResult.Answers[optionIndex];

                newAnswerResult.Answers[optionIndex].AnswerId   = pollingAnswer.Answer;
                newAnswerResult.Answers[optionIndex].AnswerText = pollingAnswer.AnswerText;
            }

            return(exportToCSV(pollingCustomView));
        }