public ActionResult Index() { var viewModel = new ClaimsIndexViewModel() { Claims = claimedActionsProvider.GetClaimGroups(), }; return(View(viewModel)); }
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)); }
public async Task <ActionResult> ViewClaims(String id) { var user = await userManager.FindByIdAsync(id); var userRoles = await userManager.GetRolesAsync(id); var userclaims = new List <Claim>(); foreach (var role in userRoles) { var roleClaims = await roleManager.GetClaimsAsync(role); userclaims.AddRange(roleClaims); } var claimGroups = claimedActionsProvider.GetClaimGroups(); var viewModel = new UserClaimsViewModel() { UserName = user.UserName, }; foreach (var claimGroup in claimGroups) { var claimGroupModel = new UserClaimsViewModel.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 = userclaims.Any(ac => ac.Type == claimGroup.GroupId.ToString() && ac.Value == c) }).ToList() }; viewModel.ClaimGroups.Add(claimGroupModel); } return(View(viewModel)); }