Making a REAL web application with ASP.NET Web API Part 1, the data
7/31/2012Short and sweet is how this one is going to roll out since I have covered Entity Framework code first approach a couple of times already. So here is the code I used to set up my objects that I will be interacting with for the web api / handlebars.js demo:
public class Onus { public virtual int Id { get; set; } public virtual string Title { get; set; } public virtual string Description { get; set; } public virtual string Details { get; set; } public virtual DateTime? DueDate { get; set; } public virtual string Status { get; set; } }
Nothing fancy here, and obviously a very dumbed down version. I expect and the functionality grows this will become three or for different entities, but for the sake of getting things off the ground for testing the ASP.NET web api, this suits just fine.
Next step is to throw it into you DbContext class:
public DbSetOnuses { get; set; }
Then you can go ahead and update the database to contain this table. (If you are starting from scratch refer to this post for more details on code-first set up)
That is all for now, this little demo project has turned into the project from hell with all the silly javascript debugging I have been going through, but progress is being made. Next I will show you how I set up my API controller to respond appropriately to the web api requests, and then I will go into the javascript to hit the web api url and throw the results into some handlebars.js templates.
If you are curious about the web api side of things I have a very general post on getting one up and running in about 5 minutes. You can read that here