Esempio n. 1
0
        /// <summary>
        /// Recherche une propriété et son attribute ForeignKeyJsonApi à partir du nom de relation
        /// </summary>
        public static Tuple <PropertyInfo, ForeignKeyJsonApiAttribute> FindForeignKeyPropertyAndAttribute(Type type, string nomRelation)
        {
            foreach (PropertyInfo prop in type.GetProperties())
            {
                ForeignKeyJsonApiAttribute attr = prop.GetCustomAttribute <ForeignKeyJsonApiAttribute>();

                if (attr != null && attr.RelationName == nomRelation)
                {
                    return(new Tuple <PropertyInfo, ForeignKeyJsonApiAttribute>(prop, attr));
                }
            }

            return(new Tuple <PropertyInfo, ForeignKeyJsonApiAttribute>(null, null));
        }
Esempio n. 2
0
        public RelationsPropertyEngine(
            IServiceProvider serviceProvider,
            IQueryService queryService,
            InformationRessource informationRessource,
            PropertyInfo propertyRelation,
            RelationshipJsonApiAttribute relationshipJApiAttribute,
            string _relationPath,
            int depth)
        {
            this._serviceProvider      = serviceProvider;
            this._queryService         = queryService;
            this._informationRessource = informationRessource;
            this._relationProperty     = propertyRelation;
            this._relationAttribute    = relationshipJApiAttribute;
            this._depth        = depth;
            this._relationPath = _relationPath;

            (PropertyInfo foreignKeyProperty, ForeignKeyJsonApiAttribute foreignKeyAttribute) =
                AttributeRelationsHandling.FindForeignKeyPropertyAndAttribute(this._informationRessource.TypeRessource, this._relationProperty.Name);

            if (foreignKeyProperty == null && foreignKeyAttribute == null)
            {
                throw new JsonApiArchitectureException($"ForeignKeyJsonApi manquant pour {this._relationProperty.Name} dans {this._informationRessource.TypeRessource.Name}, ajouter[ForeignKeyJsonApi (RelationName = nameof({this._relationProperty.Name}))]");
            }

            this._identifiantRelationProperty = AttributeHandling.GetIdProperty(typeof(T));

            if (this._identifiantRelationProperty == null)
            {
                throw new JsonApiArchitectureException($"Ajouter [IdJsonApi] sur {typeof(T).Name}");
            }

            this._foreignKeyProperty  = foreignKeyProperty;
            this._foreignKeyAttribute = foreignKeyAttribute;
            this._typeRelation        = this._relationAttribute is HasManyJsonApiAttribute ? TypeRelation.Many : TypeRelation.One;

            this.GetRelations();
        }