Ejemplo n.º 1
0
        protected PropertyInfo FindSecondaryForeignKeyProperty()
        {
            IEnumerable <PropertyInfo> idsProperties = AttributeHandling.GetIdsProperties(typeof(TRessource));

            //Si plus de 2 clés primaire, on ne peut pas définir instinctivement la seconde clé étrangere
            if (idsProperties.Count() > 2)
            {
                return(null);
            }

            return(idsProperties.FirstOrDefault(prop => prop != this.PrimaryForeigneKeyProperty));
        }
Ejemplo n.º 2
0
        public virtual async Task <IActionResult> UpdateRessource(int id, [IdArgumentJsonApi] int idRelation, TRessource ressource)
        {
            new RelationsEngine(this.HttpContext.RequestServices, this._queryService, ressource).SaveRelation();

            try {
                AssignIdsInRessource(ressource, id, idRelation, out PropertyInfo secondaryForeigneKeyProperty);

                int idTemp = await this._repository.UpdateAsync(ressource);

                if (AttributeHandling.GetIdsProperties(typeof(TRessource)).Count() == 1)
                {
                    idRelation = idTemp;
                }
                else
                {
                    idRelation = int.Parse(secondaryForeigneKeyProperty.GetValue(ressource).ToString());
                }
            } catch (NotImplementedException) {
                return(NotFound());
            }

            return(await this.GetRessource(id, idRelation));
        }