示例#1
0
        private async Task <bool> HandleAddedPermissions(
            IEnumerable <RolePermissionMappingIdentityViewModel> permissionMappings,
            IEnumerable <int> grantedPermissionIds,
            long roleId,
            long actionId,
            CancellationToken cancellationToken)
        {
            var addedPermissionIds = grantedPermissionIds
                                     .Except(permissionMappings.Select(x => x.PermissionId))
                                     .ToArray();

            if (!addedPermissionIds.Any())
            {
                return(false);
            }

            RolesLogMessages.RolePermissionMappingsCreating(_logger, roleId, addedPermissionIds);
            var mappingIds = await _rolesRepository.CreatePermissionMappingsAsync(
                roleId,
                addedPermissionIds,
                actionId,
                cancellationToken);

            RolesLogMessages.RolePermissionMappingsCreated(_logger, roleId, mappingIds);

            return(true);
        }