示例#1
0
        public async System.Threading.Tasks.Task <IHttpActionResult> EditClaimsAsync(string id)
        {
            var role = await _roleManager.FindByIdAsync(id);

            var claimGroups = _claimedActionsProvider.GetClaimGroups();

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

            var result = 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 SelectListViewModel()
                    {
                        Value    = String.Format("{0}#{1}", claimGroup.GroupId, c),
                        Text     = c,
                        Selected = assignedClaims.Any(ac => ac.Type == claimGroup.GroupId.ToString() && ac.Value == c)
                    }).ToList()
                };
                result.ClaimGroups.Add(claimGroupModel);
            }
            return(CCOk(result));
        }
示例#2
0
        public async Task <IHttpActionResult> Get()
        {
            var claimPrincipal = ((ApiController)ActionContext.ControllerContext.Controller).User as ClaimsPrincipal;
            var rol            = claimPrincipal.Claims.FirstOrDefault(x => x.Type.ToLower() == "rol");

            if (rol == null)
            {
                throw new Exception("No existe");
            }


            var role = await _roleManager.FindByNameAsync(rol.Value);

            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(Ok(viewModel));
        }