Пример #1
0
        public ActionResult EditOneToMany(string entityName, int relationId)
        {
            if (!Services.Authorizer.Authorize(Permissions.EditContent, T("Not allowed to edit a content.")))
            {
                return(new HttpUnauthorizedResult());
            }

            var oneToMany = _relationshipService.GetOneToMany(relationId);

            if (oneToMany == null || oneToMany.Id == 0)
            {
                return(ResponseError("Relationship not found"));
            }
            var part   = _contentDefinitionManager.GetPartDefinition(oneToMany.Relationship.RelatedEntity.Name);
            var fields = part == null
                ? new List <SelectListItem>()
                : part.Fields.Select(x => new SelectListItem {
                Text = x.DisplayName, Value = x.Name
            });

            return(View("CreateOneToMany", new OneToManyRelationshipModel {
                IsCreate = false,
                Name = oneToMany.Relationship.Name,
                DeleteOption = (OneToManyDeleteOption)oneToMany.DeleteOption,
                PrimaryEntity = oneToMany.Relationship.PrimaryEntity.Name,
                RelatedEntity = oneToMany.Relationship.RelatedEntity.Name,
                RelatedListLabel = oneToMany.RelatedListLabel,
                ShowRelatedList = oneToMany.ShowRelatedList,
                ColumnFieldList = oneToMany.RelatedListProjection.LayoutRecord.Properties.Select(x => x.GetFiledName()).ToArray(),
                Fields = fields
            }));
        }
Пример #2
0
        private IEnumerable <RelatedEntityViewModel> GetRelationships(string contentType)
        {
            var records = _relationshipService.GetRelationships(contentType)
                          .Where(x => (x.PrimaryEntity.Name == contentType) ||
                                 ((RelationshipType)x.Type) == RelationshipType.ManyToMany).ToList();

            var pluralService = PluralizationService.CreateService(new CultureInfo("en-US"));

            foreach (var record in records)
            {
                var relationshipType = (RelationshipType)record.Type;

                if (relationshipType == RelationshipType.OneToMany)
                {
                    var oneToMany = _relationshipService.GetOneToMany(record.Id);
                    if (oneToMany.ShowRelatedList)
                    {
                        yield return(new RelatedEntityViewModel {
                            RelationId = _relationshipService.GetReferenceField(record.RelatedEntity.Name, record.Name),
                            RelationType = "OneToMany",
                            Label = oneToMany.RelatedListLabel,
                            RelatedEntityName = pluralService.Pluralize(record.RelatedEntity.Name),
                            ProjectionId = oneToMany.RelatedListProjection.Id
                        });
                    }
                }
                else
                {
                    var manyToMany        = _relationshipService.GetManyToMany(record.Id);
                    var relatedEntityName = record.PrimaryEntity.Name == contentType ? record.RelatedEntity.Name : record.PrimaryEntity.Name;
                    var projectionId      = record.PrimaryEntity.Name == contentType ? manyToMany.RelatedListProjection.Id : manyToMany.PrimaryListProjection.Id;
                    var label             = record.PrimaryEntity.Name == contentType ? manyToMany.RelatedListLabel : manyToMany.PrimaryListLabel;
                    var showList          = record.PrimaryEntity.Name == contentType ? manyToMany.ShowRelatedList : manyToMany.ShowPrimaryList;
                    if (showList)
                    {
                        yield return(new RelatedEntityViewModel {
                            RelationId = record.Name,
                            RelationType = "ManyToMany",
                            Label = label,
                            RelatedEntityName = pluralService.Pluralize(relatedEntityName),
                            ProjectionId = projectionId
                        });
                    }
                }
            }
        }