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); }
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)); }
private string BuildRelationshipPath(string parentRelationshipPath, IRelationshipMapping relationship) { if (string.IsNullOrEmpty(parentRelationshipPath)) { return(relationship.RelatedBaseResourceType); } else { return($"{parentRelationshipPath}.{relationship.RelatedBaseResourceType}"); } }
private string BuildRelationshipPath(string parentRelationshipPath, IRelationshipMapping relationship) { if (string.IsNullOrEmpty(parentRelationshipPath)) { return relationship.RelatedBaseResourceType; } else { return $"{parentRelationshipPath}.{relationship.RelatedBaseResourceType}"; } }
public ILink RelationshipSelfLink(Context context, string resourceId, IResourceMapping resourceMapping, IRelationshipMapping linkMapping) { return new SimpleLink(new Uri("http://example.com")); }
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; }
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))); }