Ejemplo n.º 1
0
        public async Task<ActionResult> EditClaims(string id)
        {
            var role = await roleManager.FindByIdAsync(id);

            var claimGroups = claimedActionsProvider.GetClaimGroups();

            var assignedClaims = await roleManager.GetClaimsAsync(role.Name);

            var viewModel = new RoleClaimsViewModel()
            {
                RoleId = role.Id,
                RoleName = role.Name,
            };

            foreach (var claimGroup in claimGroups)
            {
                var claimGroupModel = new RoleClaimsViewModel.ClaimGroup()
                {
                    GroupId = claimGroup.GroupId,
                    GroupName = claimGroup.GroupName,
                    GroupClaimsCheckboxes = claimGroup.Claims
                        .Select(c => new SelectListItem()
                        {
                            Value = String.Format("{0}#{1}", claimGroup.GroupId, c),
                            Text = c,
                            Selected = assignedClaims.Any(ac => ac.Type == claimGroup.GroupId.ToString() && ac.Value == c)
                        }).ToList()
                };
                viewModel.ClaimGroups.Add(claimGroupModel);
            }


            return View(viewModel);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> EditClaims(string id)
        {
            var role = await roleManager.FindByIdAsync(id);

            var claimGroups = claimedActionsProvider.GetClaimGroups();

            var assignedClaims = await roleManager.GetClaimsAsync(role.Name);

            var viewModel = new RoleClaimsViewModel()
            {
                RoleId   = role.Id,
                RoleName = role.Name,
            };

            foreach (var claimGroup in claimGroups)
            {
                var claimGroupModel = new RoleClaimsViewModel.ClaimGroup()
                {
                    GroupId               = claimGroup.GroupId,
                    GroupName             = claimGroup.GroupName,
                    GroupClaimsCheckboxes = claimGroup.Claims
                                            .Select(c => new SelectListItem()
                    {
                        Value    = String.Format("{0}#{1}", claimGroup.GroupId, c),
                        Text     = c,
                        Selected = assignedClaims.Any(ac => ac.Type == claimGroup.GroupId.ToString() && ac.Value == c)
                    }).ToList()
                };
                viewModel.ClaimGroups.Add(claimGroupModel);
            }


            return(View(viewModel));
        }