示例#1
0
        public string CreateRelationship(OneToManyRelationshipModel oneToMany)
        {
            if (oneToMany == null)
            {
                return("Invalid model.");
            }
            var primaryEntity = _contentMetadataService.GetEntity(oneToMany.PrimaryEntity);
            var relatedEntity = _contentMetadataService.GetDraftEntity(oneToMany.RelatedEntity);

            if (primaryEntity == null || relatedEntity == null ||
                !primaryEntity.HasPublished())
            {
                return("Invalid entity");
            }
            if (RelationshipExists(oneToMany.Name))
            {
                return("Name already exist.");
            }

            var relationship = CreateRelation(new RelationshipRecord {
                Name          = oneToMany.Name,
                PrimaryEntity = primaryEntity.Record,
                RelatedEntity = relatedEntity.Record,
                Type          = (byte)RelationshipType.OneToMany
            });

            var updateModel = new ReferenceUpdateModel(new ReferenceFieldSettings {
                AlwaysInLayout   = oneToMany.AlwaysInLayout,
                ContentTypeName  = oneToMany.PrimaryEntity,
                DisplayAsLink    = oneToMany.DisplayAsLink,
                HelpText         = oneToMany.HelpText,
                IsAudit          = oneToMany.IsAudit,
                Required         = oneToMany.Required,
                RelationshipId   = relationship.Id,
                RelationshipName = relationship.Name
            });
            var fieldViewModel = new AddFieldViewModel {
                AddInLayout   = true,
                Name          = oneToMany.FieldName,
                DisplayName   = oneToMany.FieldLabel,
                FieldTypeName = "ReferenceField"
            };

            _contentMetadataService.CreateField(relatedEntity, fieldViewModel, updateModel);

            var fieldRecord    = relatedEntity.FieldMetadataRecords.FirstOrDefault(field => field.Name == oneToMany.FieldName);
            var projectionPart = CreateProjection(oneToMany.RelatedEntity, oneToMany.ColumnFieldList);

            _oneToManyRepository.Create(new OneToManyRelationshipRecord {
                DeleteOption          = (byte)oneToMany.DeleteOption,
                LookupField           = fieldRecord,
                RelatedListProjection = projectionPart.Record,
                RelatedListLabel      = oneToMany.RelatedListLabel,
                Relationship          = relationship,
                ShowRelatedList       = oneToMany.ShowRelatedList
            });

            return(relationship.Id.ToString());
        }
示例#2
0
        public string CreateRelationship(OneToManyRelationshipModel oneToMany) {
            if (oneToMany == null) {
                return "Invalid model.";
            }
            var primaryEntity = _contentMetadataService.GetEntity(oneToMany.PrimaryEntity);
            var relatedEntity = _contentMetadataService.GetDraftEntity(oneToMany.RelatedEntity);
            if (primaryEntity == null || relatedEntity == null
                || !primaryEntity.HasPublished()) {
                return "Invalid entity";
            }
            if (RelationshipExists(oneToMany.Name)) {
                return "Name already exist.";
            }

            var relationship = CreateRelation(new RelationshipRecord {
                Name = oneToMany.Name,
                PrimaryEntity = primaryEntity.Record,
                RelatedEntity = relatedEntity.Record,
                Type = (byte) RelationshipType.OneToMany
            });

            var updateModel = new ReferenceUpdateModel(new ReferenceFieldSettings {
                AlwaysInLayout = oneToMany.AlwaysInLayout,
                ContentTypeName = oneToMany.PrimaryEntity,
                DisplayAsLink = oneToMany.DisplayAsLink,
                HelpText = oneToMany.HelpText,
                IsAudit = oneToMany.IsAudit,
                Required = oneToMany.Required,
                RelationshipId = relationship.Id,
                RelationshipName = relationship.Name
            });
            var fieldViewModel = new AddFieldViewModel {
                AddInLayout = true,
                Name = oneToMany.FieldName,
                DisplayName = oneToMany.FieldLabel,
                FieldTypeName = "ReferenceField"
            };
            _contentMetadataService.CreateField(relatedEntity, fieldViewModel, updateModel);

            var fieldRecord = relatedEntity.FieldMetadataRecords.FirstOrDefault(field => field.Name == oneToMany.FieldName);
            var projectionPart = CreateProjection(oneToMany.RelatedEntity, oneToMany.ColumnFieldList);

            _oneToManyRepository.Create(new OneToManyRelationshipRecord {
                DeleteOption = (byte) oneToMany.DeleteOption,
                LookupField = fieldRecord,
                RelatedListProjection = projectionPart.Record,
                RelatedListLabel = oneToMany.RelatedListLabel,
                Relationship = relationship,
                ShowRelatedList = oneToMany.ShowRelatedList
            });

            return relationship.Id.ToString();
        }
示例#3
0
        ///<summary> 
        /// Lookup field not implemented
        ///</summary>
        public string CreateRelationship(OneToManyRelationshipModel oneToMany) {
            if (oneToMany == null) {
                return "Invalid model.";
            }
            var primaryEntity = _contentPartRepository.Table.FirstOrDefault(entity => entity.Name == oneToMany.PrimaryEntity);
            var relatedEntity = _contentPartRepository.Table.FirstOrDefault(entity => entity.Name == oneToMany.RelatedEntity);
            if (primaryEntity == null || relatedEntity == null
                || primaryEntity.Id == relatedEntity.Id) {
                return "Invalid entity";
            }
            if (RelationshipExists(oneToMany.Name)) {
                return "Name already exist.";
            }

            var relationship = CreateRelation(new RelationshipRecord {
                Name = oneToMany.Name,
                PrimaryEntity = primaryEntity,
                RelatedEntity = relatedEntity,
                Type = (byte) RelationshipType.OneToMany
            });

            var updateModel = new ReferenceUpdateModel(new ReferenceFieldSettings {
                AlwaysInLayout = oneToMany.AlwaysInLayout,
                ContentTypeName = oneToMany.PrimaryEntity,
                DisplayAsLink = oneToMany.DisplayAsLink,
                HelpText = oneToMany.HelpText,
                IsAudit = oneToMany.IsAudit,
                IsSystemField = false,
                ReadOnly = false,
                Required = oneToMany.Required,
                RelationshipId = relationship.Id,
                RelationshipName = relationship.Name
            });
            _contentDefinitionService.AddFieldToPart(oneToMany.FieldName, oneToMany.FieldLabel, "ReferenceField", relatedEntity.Name);
            _contentDefinitionService.AlterField(relatedEntity.Name, oneToMany.FieldName, updateModel);

            _fieldEvents.OnCreated(relatedEntity.Name, oneToMany.FieldName, oneToMany.AlwaysInLayout);

            var fieldRecord = relatedEntity.ContentPartFieldDefinitionRecords.FirstOrDefault(field => field.Name == oneToMany.FieldName);
            var projectionPart = CreateProjection(oneToMany.RelatedEntity, oneToMany.ColumnFieldList);

            _oneToManyRepository.Create(new OneToManyRelationshipRecord {
                DeleteOption = (byte) oneToMany.DeleteOption,
                LookupField = fieldRecord,
                RelatedListProjection = projectionPart.Record,
                RelatedListLabel = oneToMany.RelatedListLabel,
                Relationship = relationship,
                ShowRelatedList = oneToMany.ShowRelatedList
            });

            _schemaUpdateService.CreateColumn(relatedEntity.Name, oneToMany.FieldName, "ReferenceField");
            return relationship.Id.ToString();
        }