Exemplo n.º 1
0
        // Called for action link consisting of a string interpolation format based on resource properties.
        private Link SetLinkUrl(ResourceContext context, ActionResourceLink actionLink)
        {
            var link = new Link
            {
                Href    = actionLink.FormatUrl(context.Resource),
                Methods = actionLink.Methods.ToArray()
            };

            UpdateLinkDescriptorsAndResource(context, actionLink, link);
            return(link);
        }
Exemplo n.º 2
0
        public ActionResourceLink <TResource> BuildResourceUrl(HttpMethod httpMethod, Expression <Func <TResource, string> > resourceUrl)
        {
            if (resourceUrl == null)
            {
                throw new ArgumentNullException(nameof(resourceUrl), "Resource Delegate not specified.");
            }

            var actionLink     = new ActionResourceLink <TResource>(resourceUrl);
            var linkDescriptor = new LinkDescriptor <TResource>(actionLink);

            linkDescriptor.SetMethod(httpMethod);
            return(actionLink);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a named link related for a parametrized URI containing place holds based on
        /// resource properties to be substituted at link resolution time.
        /// </summary>
        /// <param name="relName">The relation name.</param>
        /// <param name="httpMethod">The HTTP method used to invoke URI.</param>
        /// <param name="resourceUrl">Function delegate passed the resource during link resolution and
        /// returns a populated URI or partial populated URI (i.e. Template) based on the properties
        /// of the passed resourced.</param>
        /// <returns>Object used to add optional metadata to the created link.</returns>
        public LinkDescriptor <TResource> Href(string relName, HttpMethod httpMethod, Expression <Func <TResource, string> > resourceUrl)
        {
            if (string.IsNullOrWhiteSpace(relName))
            {
                throw new ArgumentException("Relation Name not specified.", nameof(relName));
            }
            if (resourceUrl == null)
            {
                throw new ArgumentNullException(nameof(resourceUrl), "Resource Delegate not specified.");
            }

            var actionLink     = new ActionResourceLink <TResource>(resourceUrl);
            var linkDescriptor = new LinkDescriptor <TResource>(actionLink);

            AddActionLink(actionLink);

            linkDescriptor.SetRelName(relName);
            linkDescriptor.SetMethod(httpMethod);
            return(linkDescriptor);
        }