Example #1
0
        private async void AddPermissionToRoleAsync(string roleName, IServiceCollection services)
        {
            RoleManager <ApplicationRole> roleManager = services.BuildServiceProvider().GetRequiredService <RoleManager <ApplicationRole> >();

            var role = await roleManager.FindByNameAsync(roleName);

            var permittedClaimList = roleManager.GetClaimsAsync(role);

            ClaimHelper claimHelper = new ClaimHelper();
            var         claimList   = claimHelper.GetAllClaimList();

            foreach (var claim in claimList)
            {
                if (!permittedClaimList.Result.Any(x => x.Type == claim.Value))
                {
                    await roleManager.AddClaimAsync(role, new Claim(claim.Value, role.Id));
                }
            }
        }