Skip to content

Instantly share code, notes, and snippets.

@jsakamoto
Created April 3, 2012 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsakamoto/2292359 to your computer and use it in GitHub Desktop.
Save jsakamoto/2292359 to your computer and use it in GitHub Desktop.
sammary of CLRH Extra session-1 sample code.
// http://atnd0.apphb.com/api/attendees
public class Attendee
{
public int AttendeeID { get; set; }
[Required, MaxLength(20)]
public string Name { get; set; }
[Required, MaxLength(20)]
public string Email { get; set; }
[MaxLength(20)]
public string TwitterID { get; set; }
public bool beParty { get; set; }
}
public class AtndDB : DbContext
{
public DbSet<Attendee> Attendees { get; set; }
}
public class MyAPIController : ApiController
{
private AtndDB db = new AtndDB();
// GET /api/myapi
public IQueryable<Attendee> Get()
{
return db.Attendees.AsQueryable();
}
}
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/attendees/{id}",
defaults: new { controller = "MyAPI", id = RouteParameter.Optional }
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment