Created
April 3, 2012 14:19
-
-
Save jsakamoto/2292359 to your computer and use it in GitHub Desktop.
sammary of CLRH Extra session-1 sample code.
This file contains 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
// 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