Exemplo n.º 1
0
        public static object GetCollection(JToken value, IRelationshipMapping mapping)
        {
            IList resultValue;

            if (!(value is JArray))
            {
                throw new InvalidOperationException("Json array expected.");
            }

            try
            {
                var array       = (JArray)value;
                var listOfItems = array
                                  .ToObject <List <string> >()
                                  .Select(id =>
                {
                    var obj = Activator.CreateInstance(mapping.ResourceMapping.ResourceRepresentationType);
                    mapping.ResourceMapping.IdSetter(obj, id);
                    return(obj);
                });

                resultValue = (IList)Activator.CreateInstance(mapping.RelatedCollectionProperty.PropertyType);
                foreach (var item in listOfItems)
                {
                    resultValue.Add(item);
                }
            }
            catch
            {
                resultValue = null;
            }
            return(resultValue);
        }
Exemplo n.º 2
0
 public ILink RelationshipRelatedLink(Context context, string resourceId, IResourceMapping resourceMapping, IRelationshipMapping linkMapping)
 {
     var selfLink = FindResourceSelfLink(context, resourceId, resourceMapping).Href;
     var completeLink = $"{selfLink}/{linkMapping.RelationshipName}";
     return new SimpleLink(new Uri(completeLink));
    
 }
Exemplo n.º 3
0
 private string BuildRelationshipPath(string parentRelationshipPath, IRelationshipMapping relationship)
 {
     if (string.IsNullOrEmpty(parentRelationshipPath))
     {
         return(relationship.RelatedBaseResourceType);
     }
     else
     {
         return($"{parentRelationshipPath}.{relationship.RelatedBaseResourceType}");
     }
 }
Exemplo n.º 4
0
 private string BuildRelationshipPath(string parentRelationshipPath, IRelationshipMapping relationship)
 { 
     if (string.IsNullOrEmpty(parentRelationshipPath))
     {
         return relationship.RelatedBaseResourceType;
     }
     else
     {
         return $"{parentRelationshipPath}.{relationship.RelatedBaseResourceType}";
     }
 }
Exemplo n.º 5
0
 public ILink RelationshipSelfLink(Context context, string resourceId, IResourceMapping resourceMapping, IRelationshipMapping linkMapping)
 {
     return new SimpleLink(new Uri("http://example.com"));
 }
Exemplo n.º 6
0
 public ILink RelationshipSelfLink(Context context, string resourceId, IResourceMapping resourceMapping, IRelationshipMapping linkMapping)
 {
     return(new SimpleLink(new Uri("http://example.com")));
 }
        public object GetCollection(JToken value, IRelationshipMapping mapping)
        {
            IList resultValue;

            if (!(value is JArray))
                throw new InvalidOperationException("Json array expected.");

            try
            {
                var array = (JArray)value;
                var listOfItems = array
                    .ToObject<List<string>>()
                    .Select(id =>
                    {
                        var obj = Activator.CreateInstance(mapping.ResourceMapping.ResourceRepresentationType);
                        mapping.ResourceMapping.IdSetter(obj, id);
                        return obj;
                    });

                resultValue = (IList)Activator.CreateInstance(mapping.RelatedCollectionProperty.PropertyType);
                foreach (var item in listOfItems)
                {
                    resultValue.Add(item);
                }
            }
            catch
            {
                resultValue = null;
            }
            return resultValue;
        }
Exemplo n.º 8
0
        public ILink RelationshipSelfLink(Context context, string resourceId, IResourceMapping resourceMapping, IRelationshipMapping linkMapping)
        {
            var selfLink     = FindResourceSelfLink(context, resourceId, resourceMapping).Href;
            var completeLink = $"{selfLink}/relationships/{linkMapping.RelationshipName}";

            return(new SimpleLink(new Uri(completeLink)));
        }