Rewrite IsParentOfChild

This commit is contained in:
ig 2023-03-09 10:52:31 +01:00
parent 683ef02704
commit 4812e371b0
2 changed files with 4 additions and 12 deletions

View File

@ -26,7 +26,6 @@ public partial class Db
return Folders.Where(f => f.ParentId == parent.Id);
}
public IEnumerable<Folder> GetDescendantFolders(Folder parent)
{
return parent.Traverse(GetChildFolders);

View File

@ -30,17 +30,10 @@ public partial class Db
public Boolean IsParentOfChild(User parent, User child)
{
var parentPointer = child.ParentId;
if (parent.Id == child.Id)
return true;
while (parentPointer != null && parentPointer != parent.Id)
{
parentPointer = GetUserById(parentPointer).ParentId;
}
return parentPointer == parent.Id;
return child
.Unfold(u => GetUserById(u.ParentId))
.Select(u => u.Id)
.Contains(parent.Id);
}
public User? GetUserByEmail(String email) => Users.FirstOrDefault(u => u.Email == email);