Last active
January 3, 2016 12:29
-
-
Save lnickers2004/8463611 to your computer and use it in GitHub Desktop.
WebAPI 2: Foods ApiController which returns an IEnumerable type and behind-the-scenes depends upon the JSON.NET Camel Case Contract Resolver Formatter to format the JSON nicely for client consumption.
NOTE: we still need to change this to use dependency Injection of an Entity Repository-- to make for better decopling and testing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using CountingKs.Data; | |
using CountingKs.Data.Entities; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using System.Web.Http; | |
namespace CountingKs.Controllers | |
{ | |
public class FoodsController : ApiController | |
{ | |
public IEnumerable<Food> Get() | |
{ | |
var repo = new CountingKsRepository( | |
new CountingKsContext()); | |
var results = repo.GetAllFoods() | |
.OrderBy(f => f.Description) | |
.Take(25) | |
.ToList(); | |
return results; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment