// GET: api/Books public BooksLinked Get() { // Get all var fetchedObjects = m.Books.GetAll(); // Create an object to be returned BooksLinked books = new BooksLinked(); // Set its collection property books.Collection = Mapper.Map<IEnumerable<BookWithLink>>(fetchedObjects); // Set the URI request path string self = Request.RequestUri.AbsolutePath; // Add a link relation for 'self' books.Links.Add(new Link() { Rel = "self", Href = self }); // Add a link relation for each item in the collection foreach (var item in books.Collection) { item.Link = new Link() { Rel = "item", Href = string.Format("{0}/{1}", self, item.Id) }; } // Return the results return books; }
// GET: api/Books /// <summary> /// Information for all books /// </summary> /// <returns>Collection of book objects</returns> public IHttpActionResult Get() { // Get all var fetchedObjects = w.Books.GetAll(); BooksLinked result = new BooksLinked (Mapper.Map<IEnumerable<BookWithLink>>(fetchedObjects)); return Ok(result); }