示例#1
0
        public dynamic CreateChapterPractice(PracticePostModel post)
        {
            W_ChapterPractice model = new W_ChapterPractice();

            model.QuestionStore_ID = post.storeId;
            model.AddTime          = DateTime.Now;
            model.StuId            = this.SafeGetStuId;
            return(Success(mapper.CreateChapterPractice(model, post.chapterId, post.questionType, post.questionCount, post.questionSource)));
        }
示例#2
0
        /// <summary>
        /// 交卷
        /// </summary>
        /// <param name="model"></param>
        /// <param name="stuId"></param>
        /// <returns></returns>
        public bool SubmitPractice(PracticeModel model, string stuId)
        {
            W_DoExamResult result = Orm.Select <W_DoExamResult>(x => x.ID == model.resultId).FirstOrDefault();

            if (result == null)
            {
                throw new ApiException("对象错误");
            }
            else if (string.IsNullOrEmpty(stuId) || result.StuId != stuId)
            {
                throw new ApiException("登陆超时,请重新登陆");
            }
            result.EndTime = DateTime.Now;
            result.Valid   = 1;//交卷

            SqlMapper.BeginTransaction();
            try
            {
                //获取试卷题型对应的分数
                List <W_ExamPaperDetail> detailList = null;
                if (result.BusType == 0)//试卷模式
                {
                    //更新试卷测试次数
                    W_ExamPaper paper = Orm.Single <W_ExamPaper>(x => x.ID == result.BusID);
                    paper.DoCount += 1;
                    Orm.Update <W_ExamPaper>(paper);
                    //试卷题型对应得分
                    detailList = Orm.Select <W_ExamPaperDetail>(x => x.ExamPaper_ID == result.BusID).ToList();
                }
                else//更改章节练习状态
                {
                    W_ChapterPractice cp = Orm.Single <W_ChapterPractice>(x => x.ID == result.BusID);
                    cp.Status = 1;
                    Orm.Update <W_ChapterPractice>(cp);
                }
                //保存做题记录明细
                foreach (Question question in model.list)
                {
                    decimal sorce = 0;
                    if (result.BusType == 0)//试卷模式
                    {
                        W_ExamPaperDetail temp = detailList.FirstOrDefault(x => x.QuestionType_ID == question.QuestionType_ID);
                        sorce = temp != null ? temp.Sorce : 0;
                    }

                    Orm.Insert <W_DoExamResult_Detail>(new W_DoExamResult_Detail()
                    {
                        DoExamResult_ID = result.ID,
                        Question_ID     = question.ID,
                        StuID           = result.StuId,
                        MyAnswer        = question.MyAnswer,
                        Judge           = question.Judge,
                        Sorce           = sorce,
                        UpdateTime      = result.EndTime
                    });

                    //更新题目信息
                    SqlMapper.Update("UpdateQuestion", new { ID = question.ID, Judge = question.Judge, EasyWrongAnswer = question.MyAnswer });
                }

                //修改做题记录主表
                Orm.Update <W_DoExamResult>(result);

                SqlMapper.CommitTransaction();
            }
            catch
            {
                SqlMapper.RollBackTransaction();
                return(false);
            }
            return(true);
        }
示例#3
0
        /// <summary>
        /// 继续做题     做题记录页面进来,继续/重新做题    继续做题:继续原来未完成的做题记录   重新做题:开始新的做题记录,题目和原做题记录题目一致(刷新页面确保逻辑一致)
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="stuId"></param>
        /// <returns></returns>
        public dynamic ContinueChapterPractice(int ID, string stuId)
        {
            PracticeModel     rtn = new PracticeModel();
            W_ChapterPractice cp  = Orm.Single <W_ChapterPractice>(x => x.ID == ID);

            if (cp == null)
            {
                throw new ApiException("练习记录不存在或已删除");
            }
            rtn.practiceId = cp.ID;
            W_DoExamResult        result   = Orm.Single <W_DoExamResult>(x => x.BusType == 1 && x.BusID == cp.ID);
            List <Question>       list     = SqlMapper.QueryForList <Question>("GetChapterPracticeDetailQuestion", new { chapterPracticeID = cp.ID, stuId = stuId }).ToList();
            List <W_QuestionNote> NoteList = Orm.Select <W_QuestionNote>(x => x.StuID == stuId).ToList();            //题目笔记列表

            if (result.Valid == 1)                                                                                   //重新做题
            {
                W_ChapterPractice cp2 = Orm.Single <W_ChapterPractice>(x => x.Source == cp.Source && x.Status == 0); //重新做题页面刷新
                if (cp2 == null)
                {
                    string[] str = cp.Source.Split('_');
                    if (str.Length != 6)
                    {
                        throw new ApiException("练习记录数据有误");
                    }


                    W_ChapterPractice model = new W_ChapterPractice();
                    model.QuestionStore_ID = int.Parse(str[0]);
                    model.AddTime          = DateTime.Now;
                    model.StuId            = stuId;
                    //第一步,创建章节练习表W_ChapterPractice
                    W_Chapter chapter = Orm.Select <W_Chapter>(x => x.ID.ToString() == str[1]).FirstOrDefault();
                    model.Title  = chapter != null ? chapter.Name + "章节练习" + model.AddTime.ToString("yyyyMMddHHmmssfff") : "未知章节练习";
                    model.Source = cp.Source;
                    int practiceId = (int)Orm.Insert <W_ChapterPractice>(model, true);

                    //第二步,创建明细表w_chapterpractice_detail
                    foreach (Question q in list)
                    {
                        Orm.Insert <W_ChapterPractice_Detail>(new W_ChapterPractice_Detail()
                        {
                            ChapterPractice_ID = practiceId,
                            Question_ID        = q.ID
                        });
                        q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null;
                    }
                    // 第三步,创建学生做题记录主表,保存开始做题时间
                    W_DoExamResult res = new W_DoExamResult();
                    res.StuId     = model.StuId;
                    res.BusType   = 1;//章节练习
                    res.BusID     = practiceId;
                    res.BeginTime = model.AddTime;
                    res.EndTime   = model.AddTime;
                    int resultId = (int)Orm.Insert <W_DoExamResult>(res, true);

                    rtn.practiceId = practiceId;
                    rtn.resultId   = resultId;
                    rtn.list       = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList();
                }
                else
                {
                    W_DoExamResult result2 = Orm.Single <W_DoExamResult>(x => x.BusType == 1 && x.BusID == cp2.ID); if (result == null)
                    {
                        throw new ApiException("练习记录不存在或已删除");
                    }
                    rtn.resultId = result2.ID;
                    foreach (Question q in list)
                    {
                        q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null;
                    }
                    rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList();
                    //更新做题记录时间
                    result2.BeginTime = DateTime.Now;
                    Orm.Update <W_DoExamResult>(result2);
                }
            }
            else
            {
                if (result == null)
                {
                    throw new ApiException("练习记录不存在或已删除");
                }
                rtn.resultId = result.ID;
                foreach (Question q in list)
                {
                    q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null;
                }
                rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList();
                //更新做题记录时间
                result.BeginTime = DateTime.Now;
                Orm.Update <W_DoExamResult>(result);
            }
            return(rtn);
        }
示例#4
0
        /// <summary>
        /// 创建章节练习
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public PracticeModel CreateChapterPractice(W_ChapterPractice model, int chapterId, string questionType, int questionCount, int questionSource)
        {
            PracticeModel rtn = new PracticeModel();

            List <W_QuestionNote> NoteList = Orm.Select <W_QuestionNote>(x => x.StuID == model.StuId).ToList();//题目笔记列表

            //判断是重新生成章节练习还是继续之前的章节练习
            W_ChapterPractice cp = Orm.Single <W_ChapterPractice>(x => x.Source == model.QuestionStore_ID + "_" + chapterId + "_" + questionType + "_" + questionCount + "_" + questionSource + "_" + model.StuId && x.Status == 0);

            if (cp != null)//继续做题
            {
                rtn.practiceId = cp.ID;
                W_DoExamResult result = Orm.Single <W_DoExamResult>(x => x.BusType == 1 && x.BusID == cp.ID);
                if (result == null)
                {
                    throw new ApiException("练习有误,请刷新重试");
                }
                rtn.resultId = result.ID;
                List <Question> list = SqlMapper.QueryForList <Question>("GetChapterPracticeDetailQuestion", new { chapterPracticeID = cp.ID, stuId = model.StuId }).ToList();
                foreach (Question q in list)
                {
                    q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null;
                }
                rtn.list = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList();
                //更新做题记录时间
                result.BeginTime = model.AddTime;
                Orm.Update <W_DoExamResult>(result);
            }
            else//重新生成
            {
                List <Question> list = SqlMapper.QueryForList <Question>("GetChapterPracticeQuestion", new { chapterId, questionType, questionCount, questionSource, stuId = model.StuId }).ToList();
                if (list.Count == 0)
                {
                    throw new ApiException("没有更多的试题");
                }

                //第一步,创建章节练习表W_ChapterPractice
                W_Chapter chapter = Orm.Select <W_Chapter>(x => x.ID == chapterId).FirstOrDefault();
                model.Title  = chapter != null ? chapter.Name + "章节练习" + model.AddTime.ToString("yyyyMMddHHmmssfff") : "未知章节练习";
                model.Source = model.QuestionStore_ID + "_" + chapterId + "_" + questionType + "_" + questionCount + "_" + questionSource + "_" + model.StuId;
                int practiceId = (int)Orm.Insert <W_ChapterPractice>(model, true);

                //第二步,创建明细表w_chapterpractice_detail
                foreach (Question q in list)
                {
                    Orm.Insert <W_ChapterPractice_Detail>(new W_ChapterPractice_Detail()
                    {
                        ChapterPractice_ID = practiceId,
                        Question_ID        = q.ID
                    });
                    q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null;
                }
                // 第三步,创建学生做题记录主表,保存开始做题时间
                W_DoExamResult result = new W_DoExamResult();
                result.StuId     = model.StuId;
                result.BusType   = 1;//章节练习
                result.BusID     = practiceId;
                result.BeginTime = model.AddTime;
                result.EndTime   = model.AddTime;
                int resultId = (int)Orm.Insert <W_DoExamResult>(result, true);

                rtn.practiceId = practiceId;
                rtn.resultId   = resultId;
                rtn.list       = list.OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList();
            }

            return(rtn);
        }