public JsonResult GetAllQuestion(int pageSize = 10, int pageIndex = 1) { int sortID = Convert.ToInt32(Request.QueryString["sortID"]); int qType = Request.QueryString["type"].StringToInt32(); int qlevel = Request.QueryString["level"].StringToInt32(); string qKey = Request.QueryString["key"]; string qContent = Request.QueryString["content"]; //要补全 int totalCount = 0; //获取所有的试题 List <tbQuestion> qList = EQuestionBL.GetListByQuery(ref totalCount, sortID, "", qKey, int.MaxValue, 1, qType, qlevel); qList = qList.Where(p => HttpUtility.HtmlDecode(p.QuestionContent).NoHtml().Contains(qContent)).ToList(); totalCount = qList.Count; qList = qList.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList(); //获取所有的人员信息 List <Sys_User> userList = UserBL.GetList("1=1"); //获取所有试卷 List <tbExampaper> paperlist = PaperBL.GetAllExampaperList(); //知识点分类字典 Dictionary <int, tbKnowledgeKey> konwDic = KnowBL.GetAllQuestionSortDictionary(); var ListQuestion = new List <MQuestionShow>(); foreach (tbQuestion item in qList) { //调用次数 int count = 0; paperlist.ForEach(p => { if (p.QuestionList.Count(subp => subp.Qid == item._id) > 0) { count++; } }); var Question = new MQuestionShow(); Question.id = item._id; Question.QuestionContent = item.QuestionContent.NoHtml(); Question.QuestionTypeStr = ((QuestionType)item.QuestionType).ToString(); Question.QuestionLevelStr = ((QuestionLevel)item.QuestionLevel).ToString(); Question.QuestionKey = konwDic.Keys.Contains(item.QuestionKey) ? konwDic[item.QuestionKey].KeyName : ""; Question.VoidTimes = count; Question.Creater = (userList.Count == 0 || item.UserID == 0 || userList.All(p => p.UserId != item.UserID)) ? "管理员" : userList.FirstOrDefault(p => p.UserId == item.UserID).Realname; Question.CreatLocalTime = item.CreateTime.ToLocalTime().ToString("yyyy-MM-dd HH:mm"); ListQuestion.Add(Question); } return(Json(new { dataList = ListQuestion, recordCount = totalCount }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 获取所有试卷列表 /// </summary> public JsonResult GetAllExampaperList(int pageSize = 10, int pageIndex = 1) { string etitle = Request.QueryString["eTitle"].Trim(); //试卷标题 int eSortID = Convert.ToInt32(Request.QueryString["eSortID"]); //试卷库分类ID string eUser = Request.QueryString["eUser"] ?? ""; //创建者 int eExamType = Convert.ToInt32(Request.QueryString["eExamType"]); //试卷类型 try { //分类 Dictionary <int, tbExampaperSort> sortList = eSortBL.GetAllExampaperSortDictionary(); var childrenSortIDs = new List <int>(); if (eSortID != 0) { GetSortChildren(eSortID, sortList.Values.ToList(), childrenSortIDs); } List <Sys_User> userList = new UserBL().GetList("1=1"); userList = userList.Where(p => p.Realname.ToLower().Contains(eUser.ToLower())).ToList(); var temp = new int[userList.Count]; for (int r = 0; r < userList.Count; r++) { temp[r] = userList[r].UserId; } var examList = EBL.GetAllExampaperList().Where(p => (eSortID == 0 || p.ExamSortID == eSortID || childrenSortIDs.Contains(p.ExamSortID))); examList = examList.Where(p => p.ExampaperTitle.ToLower().Contains(etitle.ToLower())); examList = examList.Where(p => temp.Contains(p.UserID)); examList = examList.Where(p => (eExamType == 3 ? true : p.ExamType == eExamType)).OrderByDescending(p => p._id); List <tbExampaper> list1 = examList.Skip(((pageIndex - 1) * pageSize)).Take(pageSize).ToList(); string alluserid = null; foreach (tbExampaper itemid in list1) { alluserid += itemid.UserID + ","; } alluserid = alluserid.Remove(alluserid.LastIndexOf(","), 1); string where = string.Format("UserId IN ({0})", alluserid); List <Sys_User> userlist = new UserBL().GetList(where); var ListExampaper = new List <MExampaperShow>(); for (int j = 0; j < list1.Count(); j++) { string str = ""; if (!string.IsNullOrEmpty(list1[j].Distribution.Trim())) { string[] dislist = list1[j].Distribution.Split(','); foreach (var disstr in dislist.Select(t => t.Split(':'))) { switch (disstr[0]) { case "1": str += "问答" + disstr[1] + " "; break; case "2": str += "单选" + disstr[1] + " "; break; case "3": str += "多选" + disstr[1] + " "; break; case "4": str += "判断" + disstr[1] + " "; break; case "5": str += "填空" + disstr[1] + " "; break; case "6": str += "情景" + disstr[1] + " "; break; } } } var Exampaper = new MExampaperShow(); Exampaper.id = list1[j]._id; Exampaper.ExampaperTitle = list1[j].ExampaperTitle; Exampaper.ExamType = (list1[j].ExamType == 0) ? "普通试卷" : "随机试卷"; Exampaper.ExampaperScore = list1[j].ExampaperScore; Exampaper.ExamSortID = list1[j].ExamSortID; Exampaper.ExamSortTitle = sortList[list1[j].ExamSortID].Title; Exampaper.QuestionTypeList = str; Exampaper.Distribution = list1[j].Distribution; Exampaper.Description = list1[j].Description; Exampaper.LastUpdateTime = list1[j].LastUpdateTime.ToString("yyyy-MM-dd"); Exampaper.Creater = userlist.Any(p => p.UserId == list1[j].UserID) ? userlist.First(p => p.UserId == list1[j].UserID) .Realname.Replace("'", "’") : "无"; ListExampaper.Add(Exampaper); } return(Json(new { dataList = ListExampaper, recordCount = examList.Count() }, JsonRequestBehavior.AllowGet)); } catch { return(Json(new { dataList = new object[0], recordCount = 0 }, JsonRequestBehavior.AllowGet)); } }