public async Task<List<TreeShow>> GetDepartmentTreeAll()
{
var list = _context.Department.ToList();
List<TreeShow> menus = new List<TreeShow>();
var menu = list.Where(m => m.DeptPId == 1).Select(m => new TreeShow
{
DeptPId = m.DeptPId,
DeptId = m.DeptId,
DeptName = m.DeptName
}).ToList();
GetDepartmentTree(menu);
return menu;
}
private void GetDepartmentTree(List<TreeShow> menus)
{
var list = _context.Department.ToList();
foreach (var item in menus)
{
var _list = list.Where(s => s.DeptPId == item.DeptId).Select(m => new TreeShow
{
DeptPId= item.DeptPId,
DeptId=item.DeptId,
DeptName=item.DeptName
}).ToList();
if (_list!=null)
{
item.MenuData.AddRange(_list);
GetDepartmentTree(_list);
}
}
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/289812.html