Esempio n. 1
0
        /// <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));
            }
        }