public HttpResponseMessage GetByParent(int id, string relationType = null)
        {
            var parent = EntityService.Get(id);

            if (parent == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            var relations    = (string.IsNullOrEmpty(relationType)) ? RelationService.GetByParent(parent) : RelationService.GetByParent(parent, relationType);
            var relationsRep = new RelationListRepresentation(relations.Select(CreateRepresentation).ToList(), new RelationLinkTemplate(CurrentVersionRequest));

            return(Request.CreateResponse(HttpStatusCode.OK, relationsRep));
        }
Beispiel #2
0
        public Task <HttpResponseMessage> GetByParent(int id, string relationType = null)
        {
            var parent = Services.EntityService.Get(id);

            if (parent == null)
            {
                return(Task.FromResult(Request.CreateResponse(HttpStatusCode.NotFound)));
            }

            var relations = (string.IsNullOrEmpty(relationType)) ? Services.RelationService.GetByParent(parent) : Services.RelationService.GetByParent(parent, relationType);
            var mapped    = relations.Select(CreateRepresentation).ToList();

            var relationsRep = new RelationListRepresentation(mapped);

            return(Task.FromResult(Request.CreateResponse(HttpStatusCode.OK, relationsRep)));
        }
        private Task <HttpResponseMessage> GetByChildInternal(Func <IUmbracoEntity> getEntity, string relationType = null)
        {
            var child = getEntity();

            if (child == null)
            {
                return(Task.FromResult(Request.CreateResponse(HttpStatusCode.NotFound)));
            }

            var type = Services.RelationService.GetRelationTypeByAlias(relationType);

            if (type == null)
            {
                return(Task.FromResult(Request.CreateResponse(HttpStatusCode.NotFound)));
            }


            var relations    = (string.IsNullOrEmpty(relationType)) ? Services.RelationService.GetByChild(child) : Services.RelationService.GetByChild(child, relationType);
            var mapped       = relations.Select(CreateRepresentation).ToList();
            var relationsRep = new RelationListRepresentation(mapped);

            return(Task.FromResult(Request.CreateResponse(HttpStatusCode.OK, relationsRep)));
        }
        public HttpResponseMessage GetByChild(int id, string relationType = null)
        {
            var child = EntityService.Get(id);
            if (child == null)
                return Request.CreateResponse(HttpStatusCode.NotFound);

            var relations = (string.IsNullOrEmpty(relationType)) ? RelationService.GetByChild(child) : RelationService.GetByChild(child, relationType);
            var relationsRep = new RelationListRepresentation(relations.Select(CreateRepresentation).ToList(), new RelationLinkTemplate(CurrentVersionRequest));
            return Request.CreateResponse(HttpStatusCode.OK, relationsRep);
        }