예제 #1
0
        /// <inheritdoc />
        public IOpProcessor LocateCreateService(Operation operation)
        {
            var resource = operation.GetResourceTypeName();

            var contextEntity = _context.ContextGraph.GetContextEntity(resource);
            var processor     = _processorFactory.GetProcessor <IOpProcessor>(
                typeof(ICreateOpProcessor <,>), contextEntity.EntityType, contextEntity.IdentityType
                );

            return(processor);
        }
        private object _setHasManyRelationship(object entity,
                                               PropertyInfo[] entityProperties,
                                               RelationshipAttribute attr,
                                               ContextEntity contextEntity,
                                               Dictionary <string, RelationshipData> relationships)
        {
            var entityProperty = entityProperties.FirstOrDefault(p => p.Name == attr.InternalRelationshipName);

            if (entityProperty == null)
            {
                throw new JsonApiException("400", $"{contextEntity.EntityType.Name} does not contain an relationsip named {attr.InternalRelationshipName}");
            }

            var relationshipName = attr.PublicRelationshipName;

            if (relationships.TryGetValue(relationshipName, out RelationshipData relationshipData))
            {
                var data = (List <Dictionary <string, string> >)relationshipData.ExposedData;

                if (data == null)
                {
                    return(entity);
                }

                var genericProcessor = _genericProcessorFactor.GetProcessor(attr.Type);
                var ids = relationshipData.ManyData.Select(r => r["id"]);
                genericProcessor.SetRelationships(entity, attr, ids);
            }

            return(entity);
        }
예제 #3
0
        /// <inheritdoc/>
        public IResourceHookContainer GetResourceHookContainer(DependentType dependentType, ResourceHook hook = ResourceHook.None)
        {
            /// checking the cache if we have a reference for the requested container,
            /// regardless of the hook we will use it for. If the value is null,
            /// it means there was no implementation IResourceHookContainer at all,
            /// so we need not even bother.
            if (!_hookContainers.TryGetValue(dependentType, out IResourceHookContainer container))
            {
                container = (_genericProcessorFactory.GetProcessor <IResourceHookContainer>(typeof(ResourceDefinition <>), dependentType));
                _hookContainers[dependentType] = container;
            }
            if (container == null)
            {
                return(container);
            }

            /// if there was a container, first check if it implements the hook we
            /// want to use it for.
            List <ResourceHook> targetHooks;

            if (hook == ResourceHook.None)
            {
                CheckForTargetHookExistence();
                targetHooks = _targetedHooksForRelatedEntities;
            }
            else
            {
                targetHooks = new List <ResourceHook>()
                {
                    hook
                };
            }

            foreach (ResourceHook targetHook in targetHooks)
            {
                if (ShouldExecuteHook(dependentType, targetHook))
                {
                    return(container);
                }
            }
            return(null);
        }
예제 #4
0
 public async Task UpdateRelationshipsAsync(object parent, RelationshipAttribute relationship, IEnumerable <string> relationshipIds)
 {
     var genericProcessor = _genericProcessorFactory.GetProcessor <IGenericProcessor>(typeof(GenericProcessor <>), relationship.Type);
     await genericProcessor.UpdateRelationshipsAsync(parent, relationship, relationshipIds);
 }