Beispiel #1
0
        /// <summary>
        /// Parcours les relations et appelle les repository correspondant
        /// </summary>
        public void SaveRelation()
        {
            if (!this._informationRessource.HaveType)
            {
                return;
            }

            if (this._informationRessource.IsEnum)
            {
                return;
            }

            object idRessource = AttributeHandling.GetIdProperty(this._informationRessource.TypeRessource).GetValue(this._informationRessource.Ressource);

            // Parcours des relations
            foreach (Tuple <PropertyInfo, RelationshipJsonApiAttribute> relation in AttributeRelationsHandling.GetRelationshipProperties(this._informationRessource.TypeRessource))
            {
                //Instantiation de la classe RelationSavingEngine avec son type de ressource
                Type typeRessource = relation.Item1.PropertyType.IsGenericType ? relation.Item1.PropertyType.GetGenericArguments()[0] : relation.Item1.PropertyType;
                Type typeEngine    = typeof(RelationSavingEngine <>).MakeGenericType(typeRessource);
                Activator.CreateInstance(typeEngine, new object[] {
                    this._serviceProvider,
                    this._informationRessource,
                    relation.Item1,
                    relation.Item2,
                    idRessource
                });
            }
        }
Beispiel #2
0
        /// <summary>
        /// Récupere une liste d'identifiant qui sera injectée à la classe de criteres
        /// Dans le cas d'une relation ToOne, la liste d'identifiant contiendra la liste des clés étrangeres
        /// Dans le cas d'une relation ToMany, la liste d'identifiant contiendra la liste des identifiants des ressources parentes
        /// </summary>
        private object GetListeIdentifiant()
        {
            PropertyInfo propertyInfo = this._typeRelation == TypeRelation.One ?
                                        this._foreignKeyProperty :
                                        AttributeHandling.GetIdProperty(this._informationRessource.TypeRessource);

            Type   typeListe        = typeof(List <>);
            Type   typeListeGeneric = typeListe.MakeGenericType(propertyInfo.PropertyType);
            object listeIdentifiant = Activator.CreateInstance(typeListeGeneric);

            foreach (object ressource in this._informationRessource.RessourceEnum)
            {
                typeListeGeneric.GetMethod("Add").Invoke(listeIdentifiant, new object[] { propertyInfo.GetValue(ressource) });
            }

            return(listeIdentifiant);
        }
Beispiel #3
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();
        }
Beispiel #4
0
        private void UpdateWithRepository(MethodInfo updateMethod, object repoInstance, object relationValue)
        {
            // int idRelation = (updateMethod.Invoke(repoInstance, new object[] { relationValue }) as Task<int>).GetAwaiter().GetResult();

            this._foreignKeyProperty.SetValue(this._informationRessource.Ressource, AttributeHandling.GetIdProperty(typeof(T)).GetValue(relationValue));
        }