Skip to content

Commit

Permalink
Simplify BuildTree build Func
Browse files Browse the repository at this point in the history
  • Loading branch information
lampo1024 committed May 5, 2019
1 parent 56a3c35 commit 171a3d9
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions DncZeus.Api/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,30 +150,31 @@ public static class MenuItemHelper
public static List<MenuItem> BuildTree(this List<MenuItem> menus, string selectedGuid = null)
{
var lookup = menus.ToLookup(x => x.ParentId);
Func<string, List<MenuItem>> build = null;
build = pid =>

List<MenuItem> Build(string pid)
{
return lookup[pid]
.Select(x => new MenuItem()
{
Guid = x.Guid,
ParentId = x.ParentId,
Children = build(x.Guid),
Component = x.Component ?? "Main",
Name = x.Name,
Path = x.Path,
Meta = new MenuMeta
{
BeforeCloseFun = x.Meta.BeforeCloseFun,
HideInMenu = x.Meta.HideInMenu,
Icon = x.Meta.Icon,
NotCache = x.Meta.NotCache,
Title = x.Meta.Title,
Permission = x.Meta.Permission
}
}).ToList();
};
var result = build(selectedGuid);
.Select(x => new MenuItem()
{
Guid = x.Guid,
ParentId = x.ParentId,
Children = Build(x.Guid),
Component = x.Component ?? "Main",
Name = x.Name,
Path = x.Path,
Meta = new MenuMeta
{
BeforeCloseFun = x.Meta.BeforeCloseFun,
HideInMenu = x.Meta.HideInMenu,
Icon = x.Meta.Icon,
NotCache = x.Meta.NotCache,
Title = x.Meta.Title,
Permission = x.Meta.Permission
}
}).ToList();
}

var result = Build(selectedGuid);
return result;
}

Expand Down

0 comments on commit 171a3d9

Please sign in to comment.