Rewrite IsParentOfChild
This commit is contained in:
parent
683ef02704
commit
4812e371b0
|
@ -26,7 +26,6 @@ public partial class Db
|
||||||
return Folders.Where(f => f.ParentId == parent.Id);
|
return Folders.Where(f => f.ParentId == parent.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IEnumerable<Folder> GetDescendantFolders(Folder parent)
|
public IEnumerable<Folder> GetDescendantFolders(Folder parent)
|
||||||
{
|
{
|
||||||
return parent.Traverse(GetChildFolders);
|
return parent.Traverse(GetChildFolders);
|
||||||
|
|
|
@ -30,17 +30,10 @@ public partial class Db
|
||||||
|
|
||||||
public Boolean IsParentOfChild(User parent, User child)
|
public Boolean IsParentOfChild(User parent, User child)
|
||||||
{
|
{
|
||||||
var parentPointer = child.ParentId;
|
return child
|
||||||
|
.Unfold(u => GetUserById(u.ParentId))
|
||||||
if (parent.Id == child.Id)
|
.Select(u => u.Id)
|
||||||
return true;
|
.Contains(parent.Id);
|
||||||
|
|
||||||
while (parentPointer != null && parentPointer != parent.Id)
|
|
||||||
{
|
|
||||||
parentPointer = GetUserById(parentPointer).ParentId;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parentPointer == parent.Id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public User? GetUserByEmail(String email) => Users.FirstOrDefault(u => u.Email == email);
|
public User? GetUserByEmail(String email) => Users.FirstOrDefault(u => u.Email == email);
|
||||||
|
|
Loading…
Reference in New Issue