Пример #1
0
        /// <summary>
        /// 用户答题详情
        /// </summary>
        /// <param name="logId"></param>
        /// <returns></returns>
        public async Task <IActionResult> UserAnswerLogInfo(int logId)
        {
            UserQuestionsBll bll = new UserQuestionsBll();
            var userQuestionses  = await bll.GetList(logId);

            UserAnswerBll userAnswerBll = new UserAnswerBll();
            var           userAnswers   = await userAnswerBll.GetList(logId);

            List <Questions> questionses  = new List <Questions>();
            List <Option>    options      = new List <Option>();
            OptionBll        optionBll    = new OptionBll();
            QuestionsBll     questionsBll = new QuestionsBll();

            if (userQuestionses != null)
            {
                foreach (UserQuestions userQuestionse in userQuestionses)
                {
                    var info = await questionsBll.GetByIdAsync(userQuestionse.QuestionsId);

                    if (info != null)
                    {
                        questionses.Add(info);
                    }

                    var optionlist = await optionBll.GetList(userQuestionse.QuestionsId);

                    if (optionlist != null)
                    {
                        options.AddRange(optionlist);
                    }
                }
            }

            userQuestionses = userQuestionses.OrderBy(x => x.QIndex).ToList();

            ViewBag.questionses = questionses;
            ViewBag.options     = options;
            ViewBag.userAnswers = userAnswers;

            ViewBag.isadmin = User.RoleID == 1;
            return(View(userQuestionses));
        }
Пример #2
0
        /// <summary>
        /// 开始答题
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> StartAnswer()
        {
            QuestionsBll bll   = new QuestionsBll();
            var          list1 = await bll.GetList(QuestionsTypeEnum.ChoiceOne, 90);

            var list2 = await bll.GetList(QuestionsTypeEnum.ChoiceMore, 10);

            var list3 = await bll.GetList(QuestionsTypeEnum.FillInTheBlanks, 5);

            List <Questions> list = new List <Questions>();

            if (list1 != null)
            {
                list.AddRange(list1);
            }

            if (list2 != null)
            {
                list.AddRange(list2);
            }

            list = list.OrderBy(x => x.Id).ToList();
            UserAnswerLog    log    = new UserAnswerLog();
            UserAnswerLogBll logBll = new UserAnswerLogBll();

            log.CreateTime = DateTime.Now;
            log.UserId     = User.ID;
            int logid = await logBll.AddAsync(log);

            int index = 1;
            UserQuestionsBll     uqbll      = new UserQuestionsBll();
            OptionBll            obll       = new OptionBll();
            List <Option>        optionList = new List <Option>();
            List <UserQuestions> uoList     = new List <UserQuestions>();

            foreach (Questions questionse in list)
            {
                UserQuestions userQuestions = new UserQuestions();
                userQuestions.LogId       = logid;
                userQuestions.QIndex      = index;
                userQuestions.QuestionsId = questionse.Id;
                userQuestions.Id          = await uqbll.AddAsync(userQuestions);

                index++;
                var olist = await obll.GetList(questionse.Id);

                if (olist != null)
                {
                    optionList.AddRange(olist);
                }
                uoList.Add(userQuestions);
            }

            if (list3 != null)
            {
                foreach (Questions questionse in list3)
                {
                    UserQuestions userQuestions = new UserQuestions();
                    userQuestions.LogId       = logid;
                    userQuestions.QIndex      = index;
                    userQuestions.QuestionsId = questionse.Id;
                    userQuestions.Id          = await uqbll.AddAsync(userQuestions);

                    index++;
                    uoList.Add(userQuestions);
                }
            }

            ViewBag.optionList = optionList;
            list.AddRange(list3);
            ViewBag.list = list;
            return(View(uoList));
        }