public static ActorRole ToModel(this ActorRoleRequest actorRoleContract) { return(new ActorRole { ActorId = actorRoleContract.ActorId.Value, RoleId = actorRoleContract.RoleId.Value, EntityId = actorRoleContract.EntityId.Value }); }
public async Task <IActionResult> Create([FromBody] ActorRoleRequest newRole) { var newRoleInfo = _roleController.GetById(newRole.RoleId.Value); if (newRoleInfo.ClaimScope == ClaimScope.Global) { newRole.EntityId = Platform.AllId; } if ((await _authorizationService.AuthorizeAsync(User, newRole.EntityId, HttpContext.ScopeItems(newRoleInfo.ClaimScope))).Succeeded) { var claimScope = _roleController.GetById(newRole.RoleId.Value).ClaimScope; var creatorClaims = _actorClaimController.GetActorClaimsForEntity(int.Parse(User.Identity.Name), newRole.EntityId.Value, claimScope).Select(c => c.Id).ToList(); var newClaims = _roleClaimController.GetClaimsByRole(newRole.RoleId.Value).Select(c => c.Id); if (newClaims.All(nc => creatorClaims.Contains(nc))) { var role = newRole.ToModel(); _actorRoleCoreController.Create(role); var roleContract = role.ToContract(); return(new ObjectResult(roleContract)); } } return(Forbid()); }