Example #1
0
        /// <summary>
        /// 修改试卷题型
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool UpdateExamPaperDetail(W_ExamPaperDetail model)
        {
            if (model.QuestionType_ID == 0)
            {
                throw new ApiException("题型不能为空");
            }
            if (model.Num <= 0)
            {
                throw new ApiException("题目数量不能小于1");
            }
            if (model.Sorce < 0)
            {
                throw new ApiException("题目分数不能小于0");
            }
            W_ExamPaperDetail oldModel = Orm.Single <W_ExamPaperDetail>(x => x.ID == model.ID);

            if (oldModel == null)
            {
                throw new ApiException("试卷题型不存在或者已删除");
            }
            if (oldModel.QuestionType_ID != model.QuestionType_ID || oldModel.Num != model.Num)
            {
                List <W_ExamPaperDetail_Detail> list = Orm.Select <W_ExamPaperDetail_Detail>(x => x.ExamPaper_Detail_ID == model.ID).ToList();
                if (oldModel.QuestionType_ID != model.QuestionType_ID && list.Count > 0)
                {
                    throw new ApiException("该试卷题型已添加题目,请先删除后再修改");
                }
                if (oldModel.Num != model.Num && model.Num < list.Count)
                {
                    throw new ApiException("配置的题目数量不能少于该试卷题型已添加的题目");
                }
            }
            return(Orm.Update(model) > 0);
        }
Example #2
0
        public dynamic UpdateExamPaperDetail(W_ExamPaperDetail model)
        {
            bool flag = false;

            if (model != null && model.ID > 0)
            {
                flag = mapper.UpdateExamPaperDetail(model);
            }
            return(Success(flag ? "操作成功" : "操作失败"));
        }
Example #3
0
        public dynamic DeleteExamPaperDetail(W_ExamPaperDetail model)
        {
            bool flag = false;

            if (model.ID > 0)
            {
                flag = mapper.DeleteExamPaperDetail(model.ID);
            }
            return(Success(flag ? "操作成功" : "操作失败"));
        }
Example #4
0
 /// <summary>
 /// 添加试卷题型
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public bool AddExamPaperDetail(W_ExamPaperDetail model)
 {
     if (model.QuestionType_ID == 0)
     {
         throw new ApiException("题型不能为空");
     }
     if (model.Num <= 0)
     {
         throw new ApiException("题目数量不能小于1");
     }
     if (model.Sorce < 0)
     {
         throw new ApiException("题目分数不能小于0");
     }
     return(Orm.Insert(model) > 0);
 }
Example #5
0
        /// <summary>
        /// 给试卷题型添加题目
        /// </summary>
        /// <returns></returns>
        public bool AddPaperDetailQuestions(ExamPaperPostModel model)
        {
            W_ExamPaper paper = Orm.Single <W_ExamPaper>(x => x.ID == model.examPaperId);

            if (paper == null)
            {
                throw new ApiException("试卷不存在或者已删除");
            }
            W_ExamPaperDetail paperDetail = Orm.Single <W_ExamPaperDetail>(x => x.ID == model.examPaperDetailId);

            if (paperDetail == null)
            {
                throw new ApiException("试卷题型不存在或者已删除");
            }
            if (paperDetail.ExamPaper_ID != paper.ID)
            {
                throw new ApiException("试卷题型与试卷不匹配");
            }
            List <W_ExamPaperDetail_Detail> list = Orm.Select <W_ExamPaperDetail_Detail>(x => x.ExamPaper_ID == model.examPaperId && x.ExamPaper_Detail_ID == model.examPaperDetailId).ToList();

            if (list.Count + model.questionIds.Length > paperDetail.Num)
            {
                throw new ApiException("选择的题目不能超过配置的数目");
            }
            SqlMapper.BeginTransaction();
            try
            {
                foreach (int questionId in model.questionIds)
                {
                    Orm.Insert <W_ExamPaperDetail_Detail>(new W_ExamPaperDetail_Detail()
                    {
                        ExamPaper_ID        = model.examPaperId,
                        ExamPaper_Detail_ID = model.examPaperDetailId,
                        Question_ID         = questionId
                    });
                }
                SqlMapper.CommitTransaction();
            }
            catch
            {
                SqlMapper.RollBackTransaction();
                return(false);
            }
            return(true);
        }
Example #6
0
        /// <summary>
        /// 查询未选的题目列表总条数
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public int GetNonExamPaperQuestionTotalCount(QuestionRequest request)
        {
            W_ExamPaper paper = Orm.Single <W_ExamPaper>(x => x.ID == request.ExamPaperID);

            if (paper == null)
            {
                throw new ApiException("试卷不存在或者已删除");
            }
            W_ExamPaperDetail paperDetail = Orm.Single <W_ExamPaperDetail>(x => x.ID == request.ExamPaperDetailID);

            if (paperDetail == null)
            {
                throw new ApiException("试卷题型不存在或者已删除");
            }
            if (paperDetail.ExamPaper_ID != paper.ID)
            {
                throw new ApiException("试卷题型与试卷不匹配");
            }
            return(SqlMapper.QueryForObject <int>("GetNonExamPaperQuestionTotalCount", new { examPaperId = request.ExamPaperID, examPaperDetailId = request.ExamPaperDetailID, type = paperDetail.QuestionType_ID, store = paper.QuestionStore_ID, title = request.Title, level = request.Level, pageStatus = 0 }));
        }
Example #7
0
        /// <summary>
        /// 查询未选的题目列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public IList GetNonExamPaperQuestionList(QuestionRequest request)
        {
            W_ExamPaper paper = Orm.Single <W_ExamPaper>(x => x.ID == request.ExamPaperID);

            if (paper == null)
            {
                throw new ApiException("试卷不存在或者已删除");
            }
            W_ExamPaperDetail paperDetail = Orm.Single <W_ExamPaperDetail>(x => x.ID == request.ExamPaperDetailID);

            if (paperDetail == null)
            {
                throw new ApiException("试卷题型不存在或者已删除");
            }
            if (paperDetail.ExamPaper_ID != paper.ID)
            {
                throw new ApiException("试卷题型与试卷不匹配");
            }
            return(QueryForList("GetNonExamPaperQuestionList", new { examPaperId = request.ExamPaperID, examPaperDetailId = request.ExamPaperDetailID, type = paperDetail.QuestionType_ID, store = paper.QuestionStore_ID, title = request.Title, level = request.Level, pageIndex = (request.PageIndex - 1) * request.PageSize, pageSize = request.PageSize, pageStatus = request.PageStatus }));
        }
Example #8
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);
        }