Example #1
0
        public async Task <IActionResult> CreatePermissionOnRole(RolePermissionCreateRequest request)
        {
            //Recupero l'elemento dal business layer
            var permission = AuthorizationLayer.GetPermission(request.PermissionId);

            if (permission == null)
            {
                return(NotFound($"Permission with {request.PermissionId} not found"));
            }

            //Recupero l'elemento dal business layer
            var role = AuthorizationLayer.GetRole(request.RoleId);

            if (role == null)
            {
                return(NotFound($"Role with {request.RoleId} not found"));
            }

            var entity = new PermissionRole()
            {
                PermissionId = permission.Id,
                RoleId       = role.Id
            };
            //Invocazione del service layer
            var validations = await AuthorizationLayer.CreatePermissionRole(entity, PlatformUtils.GetIdentityUserId(User));

            if (validations.Count > 0)
            {
                return(BadRequest(validations));
            }

            var permissions = AuthorizationLayer.FetchPermissionsOnRole(role.Id);

            //Return contract
            return(Ok(permissions.As(ContractUtils.GenerateContract)));
        }