0

I need to create the lambda query that allows me to get the security objects that the user (Account) is authorized to access in addition to the list of permissions assigned to him for each security object

The method is List<AuthObject> GetUserAccessList (int accountId)

The AuthObject:

 public class AuthObject
{
    public string Obj { get; set; } // name of the security object
    public List<String> Permissions { get; set; } //name of the permissions 
}

enter image description here

1 Answer 1

1

Query your data using 2 queries and then assemble them in memory.

var securityObjects = await context.SecurityObjects.Where(so => so.SecurityPermissions.Any(sp => sp.SecurityRoles.Any(sr => sr.Accounts.Any(a => a.ID == accountId)))).ToListAsync().COnfigureAwait(false);
var securityPermissionsByObjectId = (await context.SexurityPermissions.Where(sp =>sp.SecurityRoles.Any(sr => sr.Accounts.Any(a => a.ID == accountId))).ToListAsync().ConfigureAwait(false)).GroupBy(sp => sp.SecurityObjectID).ToDictionary(g => g.Key, g => g.Select(sp => sp.Name).ToList());

var result = securityObjects.Select(so => new AuthObject
{
    Obj = so.Name,
    Permissions = securityPermissionsByObjectId[so.ID]
})
.ToList();

return result;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.