Example #1
0
        public async Task <IActionResult> SetAnswerScore()
        {
            int           id         = Request.Form["id"].TryToInt(0);
            double        score      = Request.Form["score"].TryToDouble();
            UserAnswerBll bll        = new UserAnswerBll();
            var           userAnswer = await bll.GetByIdAsync(id);

            if (userAnswer != null)
            {
                userAnswer.Score = score;
                bool flag = await bll.UpdateAsync(userAnswer);

                UserAnswerLogBll userAnswerLogBll = new UserAnswerLogBll();
                var log = await userAnswerLogBll.GetById(userAnswer.LogId);

                if (log != null)
                {
                    log.TotalScore = log.TotalScore + score;
                    await userAnswerLogBll.UpdateAsync(log);
                }

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

            return(Json(new { code = 0, msg = "更新失败" }));
        }
Example #2
0
        /// <summary>
        /// 所有人答题记录
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> UserAnswerLogs(int userId = 0, int pageIndex = 1)
        {
            UserAnswerLogBll bll = new UserAnswerLogBll();
            int pageSize         = 35;
            var result           = await bll.GetList(userId, pageIndex, pageSize);

            UserBll ubll = new UserBll();

            ViewBag.userList = await ubll.GetListAsync();

            ViewBag.total     = result.Item2;
            ViewBag.userId    = userId;
            ViewBag.pageIndex = pageIndex;
            return(View(result.Item1));
        }
Example #3
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));
        }
Example #4
0
        public async Task <IActionResult> SaveUserAnswer()
        {
            UserAnswer userAnswer = new UserAnswer()
            {
                LogId      = Request.Form["LogId"].TryToInt(0),
                QuestionId = Request.Form["QuestionId"].TryToInt(0),
            };
            UserAnswerBll bll      = new UserAnswerBll();
            string        qtype    = Request.Form["qtype"].TryToString();
            string        OptionId = Request.Form["OptionIds"].TryToString();
            string        Content  = Request.Form["Content"].TryToString();
            int           isend    = Request.Form["isend"].TryToInt(0);

            OptionBll optionBll = new OptionBll();
            var       options   = await optionBll.GetList(userAnswer.QuestionId);

            int uid = 0;

            switch (qtype)
            {
            case "ChoiceMore":
                double oklength = 1;
                var    oklist   = options.Where(x => x.IsOk);
                if (oklist != null && oklist.Count() > 0)
                {
                    oklength = oklist.Count();
                }
                double scoreRat = 1 / oklength;
                var    ids      = OptionId.Split('|', StringSplitOptions.RemoveEmptyEntries);
                if (ids != null && ids.Length > 0)
                {
                    foreach (string id in ids)
                    {
                        userAnswer.OptionId = id.TryToInt();
                        userAnswer.Score    = 0;
                        if (options != null)
                        {
                            var option = options.FirstOrDefault(x => x.Id == userAnswer.OptionId);
                            if (option != null)
                            {
                                userAnswer.IsOk = option.IsOk;
                                if (option.IsOk)
                                {
                                    userAnswer.Score = scoreRat;
                                }
                            }
                        }

                        userAnswer.Id = 0;
                        uid           = await bll.AddAsync(userAnswer);
                    }
                }
                break;

            case "ChoiceOne":
                userAnswer.OptionId = OptionId.TryToInt();
                userAnswer.Score    = 0;
                var opti = options?.FirstOrDefault(x => x.Id == userAnswer.OptionId);
                if (opti != null)
                {
                    userAnswer.IsOk = opti.IsOk;
                    if (opti.IsOk)
                    {
                        userAnswer.Score = 1;
                    }
                }
                uid = await bll.AddAsync(userAnswer);

                break;

            case "FillInTheBlanks":
                userAnswer.Content = Content;
                uid = await bll.AddAsync(userAnswer);

                break;
            }

            if (isend == 1)
            {
                var ualist = await bll.GetList(userAnswer.LogId);

                var scores             = ualist.Select(x => x.Score);
                UserAnswerLogBll ulbll = new UserAnswerLogBll();
                var log = await ulbll.GetById(userAnswer.LogId);

                if (log != null)
                {
                    log.TotalScore = scores.Sum();
                    log.Duration   = (DateTime.Now - log.CreateTime).TotalMinutes;
                    await ulbll.UpdateAsync(log);
                }
            }
            return(uid > 0 ? Json(new { code = 1, msg = "Ok" }) : Json(new { code = 0, msg = "保存失败" }));
        }
Example #5
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));
        }