public ActionResult GetQuestionById(int id) { MODEL.T_Question model = OperateContext.Current.BLLSession.IQuestionBLL.GetListBy(q => q.ID == id).First(); MODEL.DTOModel.T_QuestionDTO modelDTO = model.ToDTO(); //如果是选择题,则需要查找选项 if (model.QuestionTypeID == 1) { List <MODEL.T_QuestionOption> qoList = OperateContext.Current.BLLSession .IQuestionOptionBLL.GetListBy(qo => qo.QuestionID == model.ID).ToList(); foreach (MODEL.T_QuestionOption qo in qoList) { modelDTO.T_QuestionOption.Add(qo.ToDTO()); } } MODEL.FormatModel.AjaxMsgModel jsonModel = new MODEL.FormatModel.AjaxMsgModel() { BackUrl = null, Data = modelDTO, Msg = "ok", Statu = "ok" }; return(Json(jsonModel, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 8.0 获取试卷中的题目列表 /// </summary> public ActionResult GetPaperQuestionList(int id) { List <MODEL.T_Question> list = OperateContext.Current.BLLSession .IPaperQuestionBLL.GetListBy(p => p.PaperID == id) .Select(p => p.T_Question).OrderBy(p => p.QuestionTypeID).ToList(); //如果试卷中题目为空 if (list.Count == 0) { MODEL.FormatModel.AjaxMsgModel jsonModel = new MODEL.FormatModel.AjaxMsgModel() { Data = null, BackUrl = "", Statu = "null", Msg = "该试卷并没有题目~" }; return(Json(jsonModel, JsonRequestBehavior.AllowGet)); } else { //DTO格式数据 List <MODEL.DTOModel.T_QuestionDTO> listDTO = new List <MODEL.DTOModel.T_QuestionDTO>(); foreach (MODEL.T_Question q in list) { //DTO MODEL.DTOModel.T_QuestionDTO qDTO = q.ToDTO(); //简答题 if (q.QuestionTypeID == 2) { listDTO.Add(qDTO); } else if (q.QuestionTypeID == 1) { List <MODEL.T_QuestionOption> qoList = OperateContext.Current.BLLSession .IQuestionOptionBLL.GetListBy(qo => qo.QuestionID == q.ID).ToList(); foreach (MODEL.T_QuestionOption qo in qoList) { qDTO.T_QuestionOption.Add(qo.ToDTO()); } listDTO.Add(qDTO); } } //返回JSON MODEL.FormatModel.AjaxMsgModel jsonModel = new MODEL.FormatModel.AjaxMsgModel() { Data = listDTO, BackUrl = "", Statu = "ok", Msg = "ok" }; return(Json(jsonModel, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// 2.0 返回分页数据 /// </summary> public ActionResult GetPageData() { //页码 int pageIndex = int.Parse(Request.Params["pageIndex"]); //页容量 int pageSize = int.Parse(Request.Params["pageSize"]); //试卷Id int paperId = int.Parse(Request.Params["paperId"]); //总页数 int pageCount = 0; //总记录条数 int recordCount = 0; //获取分页数据 List <MODEL.T_Question> list = OperateContext.Current.BLLSession.IQuestionBLL .GetPagedList(pageIndex, pageSize, q => q.IsDel == false, qb => qb.ID).ToList(); //转为DTOModel List <MODEL.DTOModel.T_QuestionDTO> listDTO = new List <MODEL.DTOModel.T_QuestionDTO>(); foreach (MODEL.T_Question q in list) { //限制题目内容长度 if (q.QuestionContent.Length > 45) { q.QuestionContent = q.QuestionContent.Substring(0, 45) + "..."; } //转为DTOmodel MODEL.DTOModel.T_QuestionDTO qDTO = q.ToDTO(); //判断该题目是否存在于试卷中 if (OperateContext.Current.BLLSession.IPaperQuestionBLL .GetListBy(pq => pq.PaperID == paperId & pq.QuestionID == q.ID) .FirstOrDefault() != null) { qDTO.IsAdded = true; listDTO.Add(qDTO); } else { listDTO.Add(qDTO); } } //计算总页数和总记录条数 list = OperateContext.Current.BLLSession .IQuestionBLL.GetListBy(q => q.IsDel == false).ToList(); recordCount = list.Count; if (recordCount % pageSize == 0) { pageCount = recordCount / pageSize; } else { pageCount = recordCount / pageSize + 1; } //封装为Json数据 MODEL.FormatModel.AjaxPagedModel jsonData = new MODEL.FormatModel.AjaxPagedModel() { Data = listDTO, BackUrl = null, Msg = "ok", Statu = "ok", PageCount = pageCount, RecordCount = recordCount }; ViewData["pageIndex"] = pageIndex; ViewData["pageId"] = paperId; return(Json(jsonData, JsonRequestBehavior.AllowGet)); }