I have some classes modeling a guest user account and among others the guest's state and the guest's host:
public class GuestUser
{
public string LoginID {get; set;}
public List<GuestDetails> GuestDetailsList {get; set;}
}
public class GuestDetails
{
public GuestGroupUserState State {get; set;}
public GuestCreator GuestCreator {get; set;}
public GuestUser GuestUser {get; set;}
}
public class GuestCreator
{
public string CreatorLoginID {get; set;}
public List<GuestDetails> GuestDetailsList {get; set;}
}
public enum GuestGroupUserState
{
Unknown = 0,
Active = 1,
Locked = Active << 1,
Deleted = Locked << 1
}
I want to find all GuestUsers
and the respective GuestDetails
for a given GuestCreator gc
that are not in Deleted
-State.
So far, I tried
var guestUsers = gc.GuestDetailsList
.Where(gd => gd.State != GuestGroupUserState.Deleted)
.Select(gd => gd.GuestUser);
but this obviously gives me all the GuestDetails
for the users, also the ones in Deleted
state.
Next, I tried with
var guestUsers = userRepo.GuestUsers
.Where(gu => gu.GuestDetails
.Any(gd => gd.State != GuestGroupUserState.Deleted && gd.GuestCreator.Equals(gc)));
but again this gives me all GuestDetails
for these users, including the ones in Deleted
-state.
Is there a way to get all GuestUser
s that have a GuestDetail
in non-deleted state and for these users, get only the non-deleted GuestDetail
s? If a GuestUser
has only deleted details, it shouldn't appear in the list at all. At the moment, I'm foreach()
ing through my user lists generated with the code snippets above and removing the mismatched details entries from each guest - not the most efficient way I think.