// Converts list of domain objects into C+J media type DOM // Static so it can be re-used by multiple controllers ( e.g. Sessions?topicid={topicid} and topic/{id}/sessions) public static Collection GetSessionsCollection(IEnumerable<Session> sessions, DataService dataService, HttpRequestMessage request) { var eventsCollection = new Collection(); foreach (var session in sessions) { var item = new Item(); item.Href = SessionLinkHelper.CreateLink(request,session).Target; item.Data.Add(new Data { Name = "Title", Value = session.Title }); item.Data.Add(new Data { Name = "Timeslot", Value = session.TimeslotDescription }); if (session.SpeakerId != 0) { item.Data.Add(new Data { Name = "Speaker", Value = dataService.SpeakerRepository.Get(session.SpeakerId).Name }); item.Links.Add(SpeakerLinkHelper.CreateLink(request, dataService.SpeakerRepository.Get(session.SpeakerId)).ToCJLink()); } item.Links.Add(TopicsLinkHelper.CreateLink(request, session).ToCJLink()); eventsCollection.Items.Add(item); } return eventsCollection; }
public async Task <List <SpeakerDTO> > GetAllSpeakers() { var speakersResponse = await _HttpClient.SendAsync(SpeakersLink.BuildRequestMessage()); speakersResponse.EnsureSuccessStatusCode(); WebApiContrib.CollectionJson.Collection collection = await SpeakersLink.ParseResponseAsync(speakersResponse); return(SpeakersLink.ParseSpeakers(collection)); }
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 CollectionJsonContent(Collection collection) { _serializer = JsonSerializer.Create(new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.Indented, ContractResolver = new CamelCasePropertyNamesContractResolver() }); collection.Version = "1.0"; _readDocument = new ReadDocument(collection); Headers.ContentType = new MediaTypeHeaderValue("application/vnd.collection+json"); }
private Collection CreateCollection(TimeSpan duration) { var daysCollection = new Collection(); for (int i = 1; i < duration.TotalDays; i++) { var item = new Item(); item.Data.Add(new Data {Name = "Day", Value = i.ToString()}); item.Links.Add(SessionsLinkHelper.CreateLink(Request, dayno: i).ToCJLink()); item.Links.Add(SpeakersLinkHelper.CreateLink(Request, dayno: i).ToCJLink()); item.Links.Add(TopicsLinkHelper.CreateLink(Request, dayno: i).ToCJLink()); daysCollection.Items.Add(item); } return daysCollection; }
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 ReadDocument() { Collection = new Collection(); }
public ReadDocument(Collection collection) { Collection = collection; }
public TestReadDocument() { _collection = new Collection(); _collection.Href = new Uri("http://test.com"); }