Пример #1
0
        public static IHttpActionResult CreateResponse(Speaker speakerInfo, HttpRequestMessage request)
        {
            
            if (request.Headers.Accept.Contains(new MediaTypeWithQualityHeaderValue("application/hal+json")))
            {
                return new OkResult(request)
                    .WithContent(CreateHalContent(speakerInfo, request));

            }

            // fall back to text/plain response
            return new OkResult(request)
                .WithContent(new StringContent(speakerInfo.Name + Environment.NewLine + speakerInfo.Bio))
                .WithLinkHeaders(new List<Link>
                {
                    SessionsLinkHelper.CreateLink(request, speakerInfo),
                    new IconLink() { Target = new Uri(speakerInfo.ImageUrl) }
                });
        }
Пример #2
0
        private static HttpContent CreateHalContent(Speaker speakerInfo, HttpRequestMessage request)
        {
            dynamic jspeaker = new JObject();
            jspeaker.name = speakerInfo.Name;
            jspeaker.bio = speakerInfo.Bio;

            dynamic links = new JObject();

            dynamic iconLink = new JObject();
            iconLink.href = speakerInfo.ImageUrl;
            links.icon = iconLink;

            dynamic sessionsLink = new JObject();
            sessionsLink.href = SessionsLinkHelper.CreateLink(request, speakerInfo).Target;
            links[LinkHelper.GetLinkRelationTypeName<SessionsLink>()] = sessionsLink;

            jspeaker["_links"] = links;

            return new DynamicHalContent(jspeaker);
        }
Пример #3
0
 public static SessionsLink CreateLink(HttpRequestMessage request, Speaker speaker)
 {
     return request.ResolveLink<SessionsLink>(SpeakerSessionsRoute, new { id = speaker.Id });
 }