// GET api/albums/5 public HttpResponseMessage Get(int id) { // Get one var fetchedResult = r.GetById(id); if (fetchedResult == null) { return Request.CreateResponse(HttpStatusCode.NotFound); } else { // Create an object to be returned AlbumLinked album = new AlbumLinked(); // Set its item property album.Item = AutoMapper.Mapper.Map<AlbumLink>(fetchedResult); // Get the request URI path string self = Request.RequestUri.AbsolutePath; // Add a link relation for 'self' album.Links.Add(new Link() { Rel = "self", Href = self }); // Add a link relation for the parent 'collection' List<string> u = Request.RequestUri.Segments.ToList(); album.Links.Add(new Link() { Rel = "collection", Href = u[0] + u[1] + u[2] }); // Add a link relation for 'self' in the item album.Item.Link = new Link() { Rel = "self", Href = self }; // Return the result return Request.CreateResponse<AlbumLinked>(HttpStatusCode.OK, album); } }
// GET api/albums/5 public HttpResponseMessage Get(int id) { // Get one var fetchedResult = r.GetById(id); if (fetchedResult == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } else { // Create an object to be returned AlbumLinked album = new AlbumLinked(); // Set its item property album.Item = AutoMapper.Mapper.Map <AlbumLink>(fetchedResult); // Get the request URI path string self = Request.RequestUri.AbsolutePath; // Add a link relation for 'self' album.Links.Add(new Link() { Rel = "self", Href = self }); // Add a link relation for the parent 'collection' List <string> u = Request.RequestUri.Segments.ToList(); album.Links.Add(new Link() { Rel = "collection", Href = u[0] + u[1] + u[2] }); // Add a link relation for 'self' in the item album.Item.Link = new Link() { Rel = "self", Href = self }; // Return the result return(Request.CreateResponse <AlbumLinked>(HttpStatusCode.OK, album)); } }