Beispiel #1
0
        public int CreateOneToManyRelationship(string fieldName, string relationName, string primaryEntityName, string relatedEntityName)
        {
            var primaryEntity = _contentMetadataService.GetEntity(primaryEntityName);
            var relatedEntity = _contentMetadataService.GetEntity(relatedEntityName);

            var fieldRecord = relatedEntity.FieldMetadataRecords.FirstOrDefault(field => field.Name == fieldName);

            if (fieldRecord == null)
            {
                return(-1);
            }
            var relationship = CreateRelation(new RelationshipRecord {
                Name          = relationName,
                PrimaryEntity = primaryEntity.Record,
                RelatedEntity = relatedEntity.Record,
                Type          = (byte)RelationshipType.OneToMany
            });

            var projectionPart = CreateProjection(relatedEntityName, null);

            var oneToMany = new OneToManyRelationshipRecord {
                DeleteOption          = (byte)OneToManyDeleteOption.CascadingDelete,
                LookupField           = fieldRecord,
                RelatedListProjection = projectionPart.Record,
                RelatedListLabel      = relatedEntityName,
                Relationship          = relationship,
                ShowRelatedList       = false
            };

            _oneToManyRepository.Create(oneToMany);
            return(oneToMany.Id);
        }
Beispiel #2
0
 public void DeleteRelationship(OneToManyRelationshipRecord record)
 {
     if (record == null)
     {
         return;
     }
     record.RelatedListProjection.QueryPartRecord.Layouts.Clear();
     record.RelatedListProjection.QueryPartRecord.FilterGroups.Clear();
     _oneToManyRepository.Delete(record);
     _relationshipRepository.Delete(record.Relationship);
 }