Beispiel #1
0
        public IEnumerable <Claim> GetClaimsByType(string typeName)
        {
            var claimType = ClaimTypes.Find(ct => typeName.Equals(ct.Name)).FirstOrDefault();

            if (claimType == null)
            {
                throw new ArgumentException("Claim type " + typeName + " does not exist.");
            }
            var claims = Claims.Find(c => c.ClaimTypeId == claimType.ClaimTypeId);

            return(claims);
        }
        public async Task <IActionResult> OnPostUpdate(string roleId, string roleName)
        {
            GetRole = await _roleManager.FindByIdAsync(roleId);

            GetRole.Name = roleName;

            Claims = await _roleManager.GetClaimsAsync(GetRole) as List <Claim>;

            foreach (var roleClaim in RoleClaims)
            {
                var testselect = roleClaim.Selected;
                var testclami  = roleClaim.claim;
                if (roleClaim.Selected && !Claims.Exists(x => x.Type == roleClaim.claim))
                {
                    await _roleManager.AddClaimAsync(GetRole, new Claim(roleClaim.claim, roleClaim.claim));
                }
                else if (!roleClaim.Selected && Claims.Exists(x => x.Type == roleClaim.claim))
                {
                    await _roleManager.RemoveClaimAsync(GetRole, Claims.Find(x => x.Type.Contains(roleClaim.claim)));
                }
            }
            foreach (var userClaim in UserClaims)
            {
                var testselect = userClaim.Selected;
                var testclami  = userClaim.claim;
                if (userClaim.Selected && !Claims.Exists(x => x.Type == userClaim.claim))
                {
                    await _roleManager.AddClaimAsync(GetRole, new Claim(userClaim.claim, userClaim.claim));
                }
                else if (!userClaim.Selected && Claims.Exists(x => x.Type == userClaim.claim))
                {
                    await _roleManager.RemoveClaimAsync(GetRole, Claims.Find(x => x.Type.Contains(userClaim.claim)));
                }
            }
            foreach (var versionClaim in VersionClaims)
            {
                var testselect = versionClaim.Selected;
                var testclami  = versionClaim.claim;
                if (versionClaim.Selected && !Claims.Exists(x => x.Type == versionClaim.claim))
                {
                    await _roleManager.AddClaimAsync(GetRole, new Claim(versionClaim.claim, versionClaim.claim));
                }
                else if (!versionClaim.Selected && Claims.Exists(x => x.Type == versionClaim.claim))
                {
                    await _roleManager.RemoveClaimAsync(GetRole, Claims.Find(x => x.Type.Contains(versionClaim.claim)));
                }
            }

            await _roleManager.UpdateAsync(GetRole);

            return(RedirectToPage("Index"));
        }