My goal is to share some folders to specific users groups. Groups can be AZ Security Groups or Sharepoint Groups. So, then I can add an user to a group and automatically that user can access their folders.
I can create Sharepoint Groups:
var newGroup = await context.Web.SiteGroups.AddAsync(groupName);
and I can assign this group to the web component or to a list component:
IRoleDefinition roleDefinition = subSiteContext.Web.RoleDefinitions.FirstOrDefault(r => r.Name == "Full Control");
await context.Web.AddRoleDefinitionAsync(newGroup.Id, roleDefinition);
var myList = await context.Web.Lists.GetByIdAsync(listUniqueId,p => p.RoleAssignments);
await myList.AddRoleDefinitionAsync(newGroup.Id, roleDefinition);
Both objects have .BreakRoleInheritanceAsync method (just in case I need to break inheritance from folder's parent) but Web object doesn't apply in this case because it modifies all folders and files access. And List object... i don't understand how to relate List with folders or files.
Any idea about how to deal with this? Any suggestions?