Is there a simpler and optimized way to calculate listAdminCorePriveleges
and privileges
?
public string[] GetPrivilegesForUserByPersonEntityId(int personEntityId)
{
var listPrivileges = new List<string>();
var listAdminCorePriveleges = (_accountRepository.AsQueryable()
.Where(acc => acc.PersonEntityId == personEntityId)
.Select(acc => acc.AccountAdminPositionAssignments.Where(aap => aap.IsLocked == false && aap.IsObsolete == false).Select(aap => aap.AdminPosition.AdminType.AdminPrivileges))
).AsEnumerable();
foreach (var adminCorePriveleges in listAdminCorePriveleges)
{
foreach (var adminCorePrivelege in adminCorePriveleges)
{
listPrivileges.Add(adminCorePrivelege.Name);
}
}
string[] privileges = listPrivileges.Distinct().ToArray();
return privileges;
}