Exemple #1
0
 public GetEntityDetailResult GetEntityDetail([FromBody] GetEntityDetailParams parameters)
 {
     return(_entityService.GetEntityDetail(parameters));
 }
Exemple #2
0
        public GetEntityDetailResult GetEntityDetail(GetEntityDetailParams parameters)
        {
            Throw.IfNull(parameters, nameof(parameters));

            var entityMetadata = GetEntityMetadata(parameters);

            var entity = GetEntity(entityMetadata, parameters.Keys, parameters.IncludePropertyPaths);

            var result = new GetEntityDetailResult
            {
                EntityDetail = CreateEntityComponentBase <EntityDetail>(entityMetadata, null)
            };

            result.EntityDetail.Entity     = entity;
            result.EntityDetail.Components = new List <ComponentBase>();


            foreach (var attribute in entityMetadata.Attributes)
            {
                if (attribute.IsRelationKey)
                {
                    continue;
                }
                result.EntityDetail.Components.Add(FillComponentBase(new TextBox {
                    IsReadOnly = attribute.IsKey
                }, attribute));
            }

            if (entityMetadata.Relations.IsNullOrEmpty())
            {
                return(result);
            }


            foreach (var relationInfo in entityMetadata.RelationInfos)
            {
                var relation = relationInfo.Relation;
                if (relationInfo.RelationReference != null && relationInfo.RelationReference.IsComposition)
                {
                    //Relation in composition will not be rendered because is not allowed change owner
                    continue;
                }

                if (relation.RelationType == RelationType.OneToMany)
                {
                    var entityList = CreateEntityComponentBase <EntityList>(relation.Entity, relation);
                    entityList.Attributes         = GetEntityListAttributes(relation.Entity);
                    entityList.RelationAttributes = GetRelationAttributes(relation);
                    entityList.EntityName         = relation.Entity.Name;

                    result.EntityDetail.Components.Add(entityList);
                    continue;
                }



                var entitySelector = FillComponentBase(new EntitySelector(), relation);
                entitySelector.EntityName = relation.Entity.Name;
                //TODO define better condition for display attributes
                entitySelector.DisplayAttributes = relation.Entity.Attributes.Select(x => x.Name).Take(2).ToList();
                if (!relation.Attributes.IsNullOrEmpty())
                {
                    entitySelector.RelationAttributes = GetRelationAttributes(relation);
                }
                entitySelector.IsComposition = relation.IsComposition;
                entitySelector.IsInverted    = relation.RelationType == RelationType.OneToOneInverted;
                //entitySelector.KeyAttributes = relation.Keys.Select(x => x.Name).ToList();
                result.EntityDetail.Components.Add(entitySelector);
            }



            return(result);
        }