public HttpResponseMessage Put(int id, RelationRepresentation rel)
        {
            try
            {
                var found = RelationService.GetById(id);
                if (found == null)
                    return Request.CreateResponse(HttpStatusCode.NotFound);

                Mapper.Map(rel, found);
                RelationService.Save(found);

                return Request.CreateResponse(HttpStatusCode.OK, CreateRepresentation(found));
            }
            catch (ModelValidationException exception)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, exception.Errors);
            }
        }
        private RelationRepresentation CreateRepresentation(IRelation relation)
        {
            var parentLinkTemplate = GetLinkTemplate(relation.RelationType.ParentObjectType);
            var childLinkTemplate = GetLinkTemplate(relation.RelationType.ChildObjectType);

            var rep = new RelationRepresentation(RelationLinkTemplate, parentLinkTemplate, childLinkTemplate);
            return Mapper.Map(relation, rep);
        }
 public HttpResponseMessage Post(RelationRepresentation representation)
 {
     try
     {
         var relation = Mapper.Map<IRelation>(representation);
         RelationService.Save(relation);
         return Request.CreateResponse(HttpStatusCode.OK, CreateRepresentation(relation));
     }
     catch (ModelValidationException exception)
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest, exception.Errors);
     }
 }