/// <summary> /// 搜索学习计划信息 /// </summary> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="keyword"></param> /// <param name="status"></param> /// <returns></returns> public PagerModel <StudyPlanResponse> Search(int pageSize, int pageIndex, string keyword, int?status) { StudyPlanSearch search = new StudyPlanSearch(pageIndex, pageSize, keyword, status); var result = search.Search(); var userIds = result.Table.Select(p => p.UserId); var names = UsersAccessor.GetUsernames(userIds); List <StudyPlanResponse> list = new List <StudyPlanResponse>(); foreach (var item in result.Table) { var temp = new StudyPlanResponse(item); string userName = names.ContainsKey(item.UserId) ? names[item.UserId] : string.Empty; temp.Creator = userName; list.Add(temp); } return(new PagerModel <StudyPlanResponse> { Count = result.Count, Index = result.Index, Size = result.Size, Table = list }); }
/// <summary> /// 转换数据 /// </summary> /// <param name="userPlans">用户学习计划情况集合</param> /// <returns></returns> private List <UserStudyPlanSearchResultItem> TransferData(IEnumerable <Data.Entity.UserStudyPlan> userPlans) { if (userPlans == null || userPlans.Count() < 1) { return(new List <UserStudyPlanSearchResultItem>()); } //用户学习计划ID集合 var planIds = userPlans.Select(p => p.PlanId).ToArray(); //获取所有的学习计划 var plans = StudyPlanAccessor.GetList(planIds); if (plans == null || plans.Count() < 1) { return(null); } //计划制定者ID集合 var creatorIds = plans.Select(p => p.UserId); //获取制定者名称集合 var creatorNames = UsersAccessor.GetUsernames(creatorIds); var list = new List <UserStudyPlanSearchResultItem>(); foreach (var plan in plans) { //用户学习计划执行情况 var userPlan = userPlans.FirstOrDefault(p => p.PlanId == plan.PlanId); //制定者名称 var creatorName = creatorNames[plan.UserId]; list.Add(new UserStudyPlanSearchResultItem { UserId = userPlan.UserId, PlanId = plan.PlanId, Title = plan.Title, Content = plan.Content, CreatorId = plan.UserId, Creator = creatorName, StudentCount = plan.Student, PlanStatus = plan.Status, CreateTime = plan.CreateTime, StudyStatus = userPlan.Status, Progress = userPlan.Progress, LastStudyTime = userPlan.UpdateTime }); } return(list); }