Наследование: IUrlBuilder
Пример #1
0
 private static Dictionary <string, ILink> CreateLinks(IResourceMapping resourceMapping, UrlBuilder urlBuilder, SingleResource result)
 {
     return(new Dictionary <string, ILink>()
     {
         { SelfLinkKey, new SimpleLink {
               Href = urlBuilder.GetFullyQualifiedUrl(resourceMapping.UrlTemplate.Replace(IdPlaceholder, result.Id))
           } }
     });
 }
Пример #2
0
 private static Dictionary<string, ILink> CreateLinks(IResourceMapping resourceMapping, UrlBuilder urlBuilder, SingleResource result)
 {
     return new Dictionary<string, ILink>() { { SelfLinkKey, new SimpleLink { Href = urlBuilder.GetFullyQualifiedUrl(resourceMapping.UrlTemplate.Replace(IdPlaceholder, result.Id)) } } };
 }
Пример #3
0
 private ILink GetUrlFromTemplate(string urlTemplate, string routePrefix, string parentId, string relatedId = null)
 {
     var builder = new UrlBuilder
     {
         RoutePrefix = routePrefix
     };
     return new SimpleLink
     {
         Href = builder.GetFullyQualifiedUrl(urlTemplate.Replace(ParentIdPlaceholder, parentId).Replace(RelatedIdPlaceholder, relatedId))
     };
 }
Пример #4
0
        public SingleResource CreateResourceRepresentation(object objectGraph, IResourceMapping resourceMapping, Context context)
        {
            var urlBuilder = new UrlBuilder
            {
                RoutePrefix = context.RoutePrefix
            };

            var result = new SingleResource();

            result.Id = resourceMapping.IdGetter(objectGraph).ToString();
            result.Type = resourceMapping.ResourceType;

            result.Attributes = resourceMapping.PropertyGetters.ToDictionary(kvp => kvp.Key, kvp => kvp.Value(objectGraph));

            if (resourceMapping.UrlTemplate != null)
                result.Links = CreateLinks(resourceMapping, urlBuilder, result);

            if (resourceMapping.Relationships.Any())
                result.Relationships = CreateRelationships(objectGraph, result.Id, resourceMapping, context);

            return result;
        }