예제 #1
0
        private void GenerateManyToManyParts(ManyToManyRelationshipModel manyToMany) {
            var primaryName = manyToMany.Name + manyToMany.PrimaryEntity;
            var relatedName = manyToMany.Name + manyToMany.RelatedEntity;

            _schemaUpdateService.CreateCustomTable(
                "Coevery_DynamicTypes_" + primaryName + "PartRecord",
                table => table.ContentPartRecord()
                );
            _schemaUpdateService.CreateCustomTable(
                "Coevery_DynamicTypes_" + relatedName + "PartRecord",
                table => table.ContentPartRecord()
                );
            _schemaUpdateService.CreateCustomTable(
                "Coevery_DynamicTypes_" + manyToMany.Name + "ContentLinkRecord",
                table => table.Column<int>("Id", column => column.PrimaryKey().Identity())
                    .Column<int>("PrimaryPartRecord_Id")
                    .Column<int>("RelatedPartRecord_Id")
                );

            _contentDefinitionManager.AlterPartDefinition(
                primaryName + "Part",
                builder => builder
                    .Attachable()
                    .WithSetting("DisplayName", manyToMany.RelatedListLabel));

            _contentDefinitionManager.AlterPartDefinition(
                relatedName + "Part",
                builder => builder
                    .Attachable()
                    .WithSetting("DisplayName", manyToMany.PrimaryListLabel));

            _contentDefinitionManager.AlterTypeDefinition(manyToMany.PrimaryEntity, typeBuilder => typeBuilder.WithPart(primaryName + "Part"));
            _contentDefinitionManager.AlterTypeDefinition(manyToMany.RelatedEntity, typeBuilder => typeBuilder.WithPart(relatedName + "Part"));
            _dynamicAssemblyBuilder.Build();
        }
예제 #2
0
        public string CreateRelationship(ManyToManyRelationshipModel manyToMany) {
            if (manyToMany == null) {
                return "Invalid model.";
            }
            var primaryEntity = _contentMetadataService.GetEntity(manyToMany.PrimaryEntity);
            var relatedEntity = _contentMetadataService.GetEntity(manyToMany.RelatedEntity);
            if (primaryEntity == null || relatedEntity == null
                || !primaryEntity.HasPublished() || !relatedEntity.HasPublished()) {
                return "Invalid entity";
            }
            if (RelationshipExists(manyToMany.Name)) {
                return "Name already exist.";
            }

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

            var primaryProjectionPart = CreateProjection(manyToMany.PrimaryEntity, manyToMany.PrimaryColumnList);
            var relatedProjectionPart = CreateProjection(manyToMany.RelatedEntity, manyToMany.RelatedColumnList);

            _manyToManyRepository.Create(new ManyToManyRelationshipRecord {
                PrimaryListProjection = primaryProjectionPart.Record,
                PrimaryListLabel = manyToMany.PrimaryListLabel,
                RelatedListProjection = relatedProjectionPart.Record,
                RelatedListLabel = manyToMany.RelatedListLabel,
                Relationship = relationship,
                ShowPrimaryList = manyToMany.ShowPrimaryList,
                ShowRelatedList = manyToMany.ShowRelatedList
            });

            GenerateManyToManyParts(manyToMany);
            return relationship.Id.ToString();
        }
예제 #3
0
        /// <summary>
        /// Column alter method is not the best.
        /// </summary>
        /// <param name="relationshipId"></param>
        /// <param name="manyToMany"></param>
        /// <returns>Error message string or null for correctly edited</returns>
        public string EditRelationship(int relationshipId, ManyToManyRelationshipModel manyToMany) {
            var manyToManyRecord = _manyToManyRepository.Get(record => record.Relationship.Id == relationshipId);
            if (manyToManyRecord == null) {
                return "Invalid relashionship ID.";
            }
            var relationshipRecord = manyToManyRecord.Relationship;
            manyToManyRecord.ShowPrimaryList = manyToMany.ShowPrimaryList;
            manyToManyRecord.PrimaryListLabel = manyToMany.PrimaryListLabel;
            manyToManyRecord.ShowRelatedList = manyToMany.ShowRelatedList;
            manyToManyRecord.RelatedListLabel = manyToMany.RelatedListLabel;

            var primaryPart = _contentDefinitionManager.GetPartDefinition(relationshipRecord.Name + relationshipRecord.PrimaryEntity.Name + "Part");
            primaryPart.Settings["DisplayName"] = manyToMany.RelatedListLabel;
            _contentDefinitionManager.StorePartDefinition(primaryPart);
            var relatedPart = _contentDefinitionManager.GetPartDefinition(relationshipRecord.Name + relationshipRecord.RelatedEntity.Name + "Part");
            relatedPart.Settings["DisplayName"] = manyToMany.PrimaryListLabel;
            _contentDefinitionManager.StorePartDefinition(relatedPart);

            _manyToManyRepository.Update(manyToManyRecord);

            UpdateLayoutProperties(relationshipRecord.PrimaryEntity.Name,
                manyToManyRecord.PrimaryListProjection.LayoutRecord,
                manyToMany.PrimaryColumnList);

            UpdateLayoutProperties(relationshipRecord.RelatedEntity.Name,
                manyToManyRecord.RelatedListProjection.LayoutRecord,
                manyToMany.RelatedColumnList);
            return null;
        }
예제 #4
0
        public string CreateRelationship(ManyToManyRelationshipModel manyToMany) {
            if (manyToMany == null) {
                return "Invalid model.";
            }
            var primaryEntity = _contentPartRepository.Table.FirstOrDefault(entity => entity.Name == manyToMany.PrimaryEntity);
            var relatedEntity = _contentPartRepository.Table.FirstOrDefault(entity => entity.Name == manyToMany.RelatedEntity);
            if (primaryEntity == null || relatedEntity == null || primaryEntity.Id == relatedEntity.Id) {
                return "Invalid entity";
            }
            if (RelationshipExists(manyToMany.Name)) {
                return "Name already exist.";
            }

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

            var primaryProjectionPart = CreateProjection(manyToMany.PrimaryEntity, manyToMany.PrimaryColumnList);
            var relatedProjectionPart = CreateProjection(manyToMany.RelatedEntity, manyToMany.RelatedColumnList);

            _manyToManyRepository.Create(new ManyToManyRelationshipRecord {
                PrimaryListProjection = primaryProjectionPart.Record,
                PrimaryListLabel = manyToMany.PrimaryListLabel,
                RelatedListProjection = relatedProjectionPart.Record,
                RelatedListLabel = manyToMany.RelatedListLabel,
                Relationship = relationship,
                ShowPrimaryList = manyToMany.ShowPrimaryList,
                ShowRelatedList = manyToMany.ShowRelatedList
            });

            GenerateManyToManyParts(manyToMany);
            return relationship.Id.ToString();
        }