// GET api/albums public HttpResponseMessage Get() { // Get all var fetchedResults = r.GetAll(); // Create an object to be returned AlbumsLinked albums = new AlbumsLinked(); // Set its collection property albums.Collection = AutoMapper.Mapper.Map <IEnumerable <AlbumLink> >(fetchedResults); // Get the request URI path string self = Request.RequestUri.AbsolutePath; // Add a link relation for 'self' albums.Links.Add(new Link() { Rel = "self", Href = self }); // Add a link relation for 'item' on each item in the collection foreach (var item in albums.Collection) { item.Link = new Link() { Rel = "item", Href = string.Format("{0}/{1}", self, item.Id) }; } // Return the results return(Request.CreateResponse <AlbumsLinked>(HttpStatusCode.OK, albums)); }
// GET api/albums public HttpResponseMessage Get() { // Get all var fetchedResults = r.GetAll(); // Create an object to be returned AlbumsLinked albums = new AlbumsLinked(); // Set its collection property albums.Collection = AutoMapper.Mapper.Map<IEnumerable<AlbumLink>>(fetchedResults); // Get the request URI path string self = Request.RequestUri.AbsolutePath; // Add a link relation for 'self' albums.Links.Add(new Link() { Rel = "self", Href = self }); // Add a link relation for 'item' on each item in the collection foreach (var item in albums.Collection) { item.Link = new Link() { Rel = "item", Href = string.Format("{0}/{1}", self, item.Id) }; } // Return the results return Request.CreateResponse<AlbumsLinked>(HttpStatusCode.OK, albums); }