Introduce Ancestors, GetParent
This commit is contained in:
parent
99ef91b7be
commit
8935353e38
|
@ -30,14 +30,25 @@ public partial class Db
|
|||
|
||||
public Boolean IsParentOfChild(User parent, User child)
|
||||
{
|
||||
return child
|
||||
.Unfold(GetParent)
|
||||
return Ancestors(child)
|
||||
.Any(u => u.Id == parent.Id);
|
||||
}
|
||||
|
||||
private IEnumerable<User> Ancestors(User child)
|
||||
{
|
||||
return child.Unfold(GetParent);
|
||||
}
|
||||
|
||||
public User? GetParent(User u)
|
||||
{
|
||||
return GetUserById(u.ParentId);
|
||||
return IsRoot(u)
|
||||
? null
|
||||
: GetUserById(u.ParentId);
|
||||
}
|
||||
|
||||
public static Boolean IsRoot(User u)
|
||||
{
|
||||
return u.ParentId == 0; // root has ParentId 0 by definition
|
||||
}
|
||||
|
||||
public User? GetUserByEmail(String email) => Users.FirstOrDefault(u => u.Email == email);
|
||||
|
|
Loading…
Reference in New Issue