Rewrite IsParentOfChild even shorter :P

This commit is contained in:
ig 2023-03-09 10:58:08 +01:00
parent 4812e371b0
commit 27b24b44a0
1 changed files with 7 additions and 3 deletions

View File

@ -31,9 +31,13 @@ public partial class Db
public Boolean IsParentOfChild(User parent, User child) public Boolean IsParentOfChild(User parent, User child)
{ {
return child return child
.Unfold(u => GetUserById(u.ParentId)) .Unfold(GetParent)
.Select(u => u.Id) .Any(u => u.Id == parent.Id);
.Contains(parent.Id); }
public User? GetParent(User u)
{
return GetUserById(u.ParentId);
} }
public User? GetUserByEmail(String email) => Users.FirstOrDefault(u => u.Email == email); public User? GetUserByEmail(String email) => Users.FirstOrDefault(u => u.Email == email);