Exemplo n.º 1
0
        public object Get(string entityName, int page, int rows)
        {
            var temp = _relationshipService.GetRelationships(entityName);

            //if (temp == null) {
            //    return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "The entity doesn't exist!");
            //}
            if (temp == null || temp.Length == 0)
            {
                return(new {
                    total = 0,
                    page = page,
                    records = 0,
                    rows = string.Empty
                });
            }
            var query = from record in temp
                        select new {
                ContentId     = record.Id,
                Name          = record.Name,
                PrimaryEntity = record.PrimaryEntity.Name,
                RelatedEntity = record.RelatedEntity.Name,
                Type          = ((RelationshipType)record.Type).ToString()
            };
            var totalRecords = query.Count();

            return(new {
                total = Convert.ToInt32(Math.Ceiling((double)totalRecords / rows)),
                page = page,
                records = totalRecords,
                rows = query
            });
        }
        public void OnDeleting(string entityName)
        {
            var relationships = _relationshipService.GetRelationships(entityName);

            if (relationships == null)
            {
                return;
            }
            foreach (var relationship in relationships)
            {
                _relationshipService.DeleteRelationship(relationship);
            }
        }
Exemplo n.º 3
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
                        });
                    }
                }
            }
        }