public void TestMethod1() { int page = 1; int pagesize = 5; int courseid = 10016; int lessonid = 10047; LessonUnitBll bll = new LessonUnitBll(); var pager = new Code.Common.PagingObject() { PageIndex = page, //开始页(包含) PageSize = pagesize, //条数 TotalCount = 0 }; var pages = bll.SelectUnitByNext(new Domain.Dto.Request.DtoLessonUnitSearch() { CourseID = courseid, LessonID = lessonid, StudentID = 10000, Pagination = pager }); List <int> mediaIDs = new List <int>(); List <int> textIDs = new List <int>(); var list = pages.Select(p => new Page() { pageId = p.Id, pageNum = p.Index, pageName = p.Name, steps = p.Steps.Select(s => new Step() { stepNum = s.StepNum, actions = s.Actions.Select(a => ActionTranslator.DataToViewData(a, mediaIDs, textIDs)).ToList() }).ToList() }).ToList(); //如果媒体id或文本id有值的话 if (mediaIDs.Count > 0 || textIDs.Count > 0) { ResourceBll rbll = new ResourceBll(); var medias = rbll.GetMediaObjectByIdList(mediaIDs.Distinct().ToList()); //获取所有的媒体对象字典 var texts = rbll.GetTextObjectByIdList(textIDs.Distinct().ToList()); //获取文本对象字典 list.ForEach(p => { p.steps.ForEach(s => { s.actions.ForEach(a => { ActionTranslator.SetViewDataMedia(a, medias, texts); }); }); }); } var str = JsonConvert.SerializeObject(list); }
public JsonResult GetLessonPage(DtoLessonUnitSearch search, bool isApprove = false) { LessonUnitBll bll = new LessonUnitBll(); search.StudentID = GetCurrentUser().StudentId;//设置当前学生id if (isApprove) { search.Pagination.PageSize = 1; } //如果是审批的情况,只返回一条数据 var pages = bll.SelectUnitByNext(search); List <int> mediaIDs = new List <int>(); List <int> textIDs = new List <int>(); var list = pages.Select(p => new Page() { pageId = p.Id, pageNum = p.Index, pageName = p.Name, coinsKey = Encrypt.EncryptQueryString($"{p.Coins}_{p.Id}_{p.LessonId}_{p.CourseId}"),//金币加密串(加密内容为"单元金币数_单元id_课时id_课程id")//Remark1 steps = p.Steps.Select(s => new Step() { stepNum = s.StepNum, actions = s.Actions.Select(a => ActionTranslator.DataToViewData(a, mediaIDs, textIDs)).ToList() }).ToList() }).ToList(); //如果媒体id或文本id有值的话 if (mediaIDs.Count > 0 || textIDs.Count > 0) { ResourceBll rbll = new ResourceBll(); var medias = rbll.GetMediaObjectByIdList(mediaIDs.Distinct().ToList(), true); //获取所有的媒体对象字典 var texts = rbll.GetTextObjectByIdList(textIDs.Distinct().ToList()); //获取文本对象字典 list.ForEach(p => { p.steps.ForEach(s => { s.actions.ForEach(a => { ActionTranslator.SetViewDataMedia(a, medias, texts); }); }); }); } return(Json(new JsonResponse <List <Page> > { State = true, ErrorCode = 0, ErrorMsg = "", Data = list })); }