Esempio n. 1
0
        public async Task <IActionResult> DelQuestion(int id)
        {
            QuestionsBll bll  = new QuestionsBll();
            var          info = await bll.GetByIdAsync(id);

            if (info != null)
            {
                bool flag = await bll.DelAsync(info);

                OptionBll obll = new OptionBll();
                var       list = await obll.GetList(id);

                if (list != null)
                {
                    foreach (Option option in list)
                    {
                        await obll.DelAsync(option);
                    }
                }

                if (flag)
                {
                    return(Json(new { code = 1, msg = "OK" }));
                }
            }
            return(Json(new { code = 0, msg = "删除失败" }));
        }
Esempio n. 2
0
        public async Task <IActionResult> Index(int pageIndex = 1)
        {
            int          pageSize = 35;
            QuestionsBll bll      = new QuestionsBll();
            var          result   = await bll.GetList(pageIndex, pageSize);

            ViewBag.total = result.Item2;
            List <Questions> list = result.Item1;

            ViewBag.pageIndex = pageIndex;
            return(View(list));
        }
Esempio n. 3
0
        public async Task <IActionResult> SaveQuestion()
        {
            string    content   = Request.Form["Content"].TryToString();
            int       QType     = Request.Form["QType"].TryToInt(1);
            Questions questions = new Questions();

            questions.QuestionsType = (QuestionsTypeEnum)QType;
            questions.Content       = content;
            QuestionsBll bll = new QuestionsBll();
            int          id  = await bll.AddAsync(questions);

            if (id > 0)
            {
                return(Json(new { code = 1, msg = "OK", id = id }));
            }

            return(Json(new { code = 0, msg = "保存失败" }));
        }
Esempio n. 4
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));
        }
Esempio n. 5
0
        /// <summary>
        /// 用户答题记录
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <returns></returns>
        public async Task <IActionResult> UserAnswerLogList(int pageIndex = 1)
        {
            UserAnswerLogBll bll = new UserAnswerLogBll();
            int pageSize         = 35;
            var result           = await bll.GetList(User.ID, pageIndex, pageSize);

            bool         flag  = false;
            QuestionsBll qbll  = new QuestionsBll();
            var          list1 = await qbll.GetList(QuestionsTypeEnum.ChoiceOne, 90);

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

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

            if (list1 != null && list1.Count == 90 && list2 != null && list2.Count == 10 && list3 != null && list3.Count == 5)
            {
                flag = true;
            }

            ViewBag.flag      = flag;
            ViewBag.total     = result.Item2;
            ViewBag.pageIndex = pageIndex;
            return(View(result.Item1));
        }
Esempio n. 6
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));
        }