Beispiel #1
0
        public NestedResource ManyToMany(Property property, string pivotName)
        {
            NestedResource resource = OneToMany(property);

            resource.Pivot = CreatePivot(this, resource, pivotName);
            return(resource);
        }
Beispiel #2
0
        public NestedResource OneToMany(Property property)
        {
            NestedResource resource = new NestedResource();

            resource.Name           = property.Noun;
            resource.Class          = property.Class;
            resource.DataModel      = DataModel;
            resource.ParentRelation = new ParentRelation(this);
            NestedResources.Add(resource);
            return(resource);
        }
Beispiel #3
0
        private bool SplitData(SeedData item, NestedResource nestedResource)
        {
            var token = item.JObject.GetValue(nestedResource.Name.Plural);

            item.JObject.Remove(nestedResource.Name.Plural);
            var dataList = GetDataList(nestedResource.Class);

            if (token is JArray array)
            {
                foreach (var o in array)
                {
                    JObject jObj = o as JObject;
                    if (jObj == null)
                    {
                        continue;
                    }
                    SeedRecord record = ToSeedRecord(nestedResource.Class, jObj);
                    var        id     = record.GetId();
                    if (!dataList.Any(d => d.SeedRecord.GetId() == id))
                    {
                        dataList.Add(new SeedData(jObj, record));
                    }
                    if (nestedResource.Pivot != null)
                    {
                        var pivotDataList = GetDataList(nestedResource.Pivot);
                        var pivotRecord   = new SeedRecord
                        {
                            Name    = nestedResource.Pivot.Name,
                            IsPivot = true,
                            Values  = new List <KeyValuePair <string, string> > {
                                new KeyValuePair <string, string>(item.SeedRecord.Name.Plural + "Id", item.SeedRecord.GetId()),
                                new KeyValuePair <string, string>(nestedResource.Name.Plural + "Id", record.GetId())
                            }
                        };
                        pivotDataList.Add(new SeedData(null, pivotRecord));
                    }
                    else
                    {
                        record.Values.Add(new KeyValuePair <string, string>(nestedResource.ParentRelation.Name + "Id", item.SeedRecord.GetId()));
                    }
                }
                return(true);
            }
            return(false);
        }