コード例 #1
0
        public JsonResult AdminGetScore(int id, int limit, int offset, string keyword, string sortOrder, string sortName)
        {
            HopuDBDataContext db  = new HopuDBDataContext();
            string            sql = AdminGetSql(id, keyword, sortName, sortOrder);
            //数据请求
            var scoreList = db.ExecuteQuery <UniteTestScore>(sql).ToList();
            List <UniteTestScore> score = new List <UniteTestScore>();

            //检测到循环引用报错,所以只能暂时这样转换一下,看以后有没有更好的办法
            //test
            foreach (var i in scoreList)
            {
                UniteTestScore a = new UniteTestScore()
                {
                    Id           = i.Id,
                    UtId         = i.UtId,
                    RealUserName = i.RealUserName,
                    UserName     = i.UserName,
                    EndTime      = i.EndTime,
                    Score        = i.Score
                };
                score.Add(a);
            }
            var totalq = score.Count;
            var rowsq  = score.Skip(offset).Take(limit);

            return(Json(new
            {
                total = totalq,
                rows = rowsq
            }, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public bool InsertScore(UniteTestScore uniteTestScoreInfo)
        {
            bool flag = false;

            try
            {
                //var uniteTestScore = new UniteTestScore
                //{
                //    UtId = uniteTestScoreInfo.UtId,
                //    RealUserName = uniteTestScoreInfo.RealUserName,
                //    UserName = uniteTestScoreInfo.UserName,
                //    EndTime = DateTime.Now,
                //    Score = uniteTestScoreInfo.Score,
                //};
                db.UniteTestScore.InsertOnSubmit(uniteTestScoreInfo);
                db.SubmitChanges();
                if (uniteTestScoreInfo.UtId > 0)
                {
                    flag = true;
                }
            }
            catch (Exception)
            {
                flag = false;
                throw;
            }
            return(flag);
        }
コード例 #3
0
 public JsonResult UifiedTest(string[] Answer, int UtId)
 {
     string UserName = User.Identity.GetUserName();
     bool commitAnswer = false;
     //判断时间是否在考试时间段内
     var timeInfo = _uniteTest.GetUniteTestInfo(UtId);
     foreach (var item in timeInfo)
     {
         //如果结束时间大于当前时间,可以提交
         if (Convert.ToDateTime(item.StartTime).AddMinutes(item.TimeLenth) > DateTime.Now.AddSeconds(-5))//给五秒的冗余时间 否则js倒计时0时提交会失败
         {
             commitAnswer = true;
             break;
         }
         else
         {
             return Json(false);
         }
     }
     if (commitAnswer)
     {
         //此处和取题目必须一样
         List<UnifiedTestNewTopicIdViewModel> answerList = _uniteTestInfo.GetUnifiedTestTopics(UtId, UserName).OrderBy(s => s.TopicID).ToList();
         //开始校验答案
         List<UnifiedTestQAViewModel> results = new List<UnifiedTestQAViewModel>();//成绩信息
         //先算出每题多少分
         double itemScore = 100F / answerList.Count;
         double sumScore = 0;
         //校验答案
         for (int i = 0; i < answerList.Count; i++)
         {
             if (answerList[i].Answer.Equals(Answer[i]))
             {
                 UnifiedTestQAViewModel resultinfo = new UnifiedTestQAViewModel
                 {
                     UserAnswer = Answer[i],
                     RealAnswer = answerList[i].Answer,
                     IsTrue = true
                 };
                 results.Add(resultinfo);
                 sumScore += itemScore;
             }
             else
             {
                 UnifiedTestQAViewModel resultinfo = new UnifiedTestQAViewModel
                 {
                     UserAnswer = Answer[i],
                     RealAnswer = answerList[i].Answer,
                     IsTrue = false
                 };
                 results.Add(resultinfo);
             }
         }
         //如果是第一次提交答案
         var UniteTestScoreInfo = _uniteTestScore.GetUniteTestScore(UtId, UserName);
         if (!UniteTestScoreInfo.Any())
         {
             //将考试结果存入数据库
             UniteTestScore uniteTestScoreInfo = new UniteTestScore
             {
                 UtId = UtId,
                 RealUserName = GetRealUserName.GetRealName(User.Identity.GetUserId()),
                 UserName = User.Identity.GetUserName(),
                 EndTime = DateTime.Now,
                 Score = Convert.ToInt32(Math.Round(sumScore, 0, MidpointRounding.AwayFromZero))
             };
             //如果存入成功
             if (_uniteTestScore.InsertScore(uniteTestScoreInfo))
             {
                 return Json(results);
             }
         }
         else
         {
             return Json(false);
         }
     }
     return Json(false);
 }