public async Task <RoleClaimsResponseResult> GetClaimsByRoleId( [FromQuery][Required] string roleId) { ApplicationRole role = await _roleManager.FindByIdAsync(roleId); if (role != null) { var result = await _roleManager.GetClaimsAsync(role); return(new RoleClaimsResponseResult() { Code = 200, Data = (from one in result select new ApplicationRoleClaim() { RoleId = roleId, ClaimType = one.Type, ClaimValue = one.Value }).ToArray() }); } return(new RoleClaimsResponseResult() { Code = 403, Message = "Role does not exists" }); }
public async Task <RoleClaimsResponseResult> GetClaimsByRoleId([FromQuery] string roleId) { return(await _roleManager.GetClaimsAsync(new ApplicationRole() { Id = roleId }) .ContinueWith <RoleClaimsResponseResult>(c => { RoleClaimsResponseResult result = new RoleClaimsResponseResult() { Code = 200 }; List <ApplicationRoleClaim> list = new List <ApplicationRoleClaim>(); if (c.IsCompleted && c.Result.Count > 0) { foreach (var c1 in c.Result) { list.Add(new ApplicationRoleClaim() { Id = IdGenerator.GenerateObjectId().ToString(), RoleId = roleId, ClaimType = c1.Type, ClaimValue = c1.Value }); } } result.Data = list.ToArray(); return result; })); }