public static HttpResponseMessage CreateResponse(Topic topicInfo, HttpRequestMessage request) { var response = request.RespondOk(); response.Content = new StringContent(topicInfo.Name); response.Headers.AddLinkHeader(SessionsLinkHelper.CreateLink(request, topicInfo)); response.Headers.AddLinkHeader(SpeakersLinkHelper.CreateLink(request, topicInfo)); return(response); }
public static IHttpActionResult CreateResponse(Topic topicInfo, HttpRequestMessage request) { var response = new OkResult(request) .WithContent(new StringContent(topicInfo.Name)) .WithLinkHeaders(new List <ILink> { SessionsLinkHelper.CreateLink(request, topicInfo), SpeakersLinkHelper.CreateLink(request, topicInfo) }); return(response); }
public static Collection GetCollection(IEnumerable <Topic> topics, HttpRequestMessage request) { var eventsCollection = new Collection(); foreach (var topic in topics) { var item = new Item(); item.Href = request.ResolveLink <TopicLink>(TopicLinkHelper.TopicByIdRoute, new { id = topic.Id }).Target; item.Data.Add(new Data { Name = "Title", Value = topic.Name }); item.Links.Add(SessionsLinkHelper.CreateLink(request, topic).ToCJLink()); eventsCollection.Items.Add(item); } return(eventsCollection); }
public static IHttpActionResult CreateResponse(IEnumerable <Speaker> speakers, HttpRequestMessage request) { var collection = new Collection(); foreach (var speaker in speakers) { var item = new Item(); item.Href = SpeakerLinkHelper.CreateLink(request, speaker).Target; item.Data.Add(new Data { Name = "Name", Value = speaker.Name }); item.Links.Add(SessionsLinkHelper.CreateLink(request, speaker).ToCJLink()); collection.Items.Add(item); } collection.Href = request.RequestUri; return(new OkResult(request) .WithContent(new CollectionJsonContent(collection))); }
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 <ILink> { SessionsLinkHelper.CreateLink(request, speakerInfo), new IconLink() { Target = new Uri(speakerInfo.ImageUrl) } })); }
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)); }