public IActionResult Index(PageParameter pageParams) { PageDataResponse <DepartmentDto> pageData = new PageDataResponse <DepartmentDto>(); var parameterExpression = System.Linq.Expressions.Expression.Parameter(typeof(Department)); var filter = (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Constant(true); if (!string.IsNullOrEmpty(pageParams.Key)) { pageParams.Key = pageParams.Key.Trim(); filter = (System.Linq.Expressions.Expression)System.Linq.Expressions.Expression.Constant(false); Guid guid = Guid.Empty; if (Guid.TryParse(pageParams.Key, out guid)) { filter = filter.GotoOrElse(parameterExpression.GotoEqual("ID", guid)); } } else { filter = filter.GotoOrElse(parameterExpression.GotoNotEqual("ID", Guid.Empty)); } if (pageParams.BeginTime != null && pageParams.EndTime != null && pageParams.BeginTime <= pageParams.EndTime) { filter = filter.GotoAndAlso(parameterExpression.GotoGreaterThanByDateTime("CreateTime", pageParams.BeginTime)); filter = filter.GotoAndAlso(parameterExpression.GotoLessThanByDateTime("CreateTime", pageParams.EndTime)); } filter = filter.GotoAndAlso(parameterExpression.GotoNotEqual("ID", ConstDefine.SuperDepartmentID)); var queryLambdaFilter = System.Linq.Expressions.Expression.Lambda <Func <Department, bool> >(filter, parameterExpression); int Count; List <DepartmentDto> List = _DepartmentAppService.PageList(queryLambdaFilter, pageParams.PageSize, pageParams.CurPage, out Count); if (List.Any()) { var depIds = List.Where(a => a.ParentId != Guid.Empty).Select(a => a.ParentId).ToArray(); var depList = _DepartmentAppService.QueryList(c => depIds.Contains(c.ID)); foreach (var item in List) { var temp = depList.FirstOrDefault(a => a.ID == item.ParentId); if (temp != null) { item.DepartmentName = temp.Name; } } } pageData.Data = List; pageData.TotalItem = Count; pageData.QueryData = pageParams; pageData.PageHTML = base.PageHtml(Count, pageParams.CurPage, pageParams.PageSize, this.HttpContext); return(View(pageData)); }