29.05.2015 Views

o_19mgorv9t13a3ko71fev19l81mqa.pdf

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

add the folders and references for both MVC and Web API applications, as shown in Figure 27-1.<br />

Figure 27-1. Creating the project with the MVC and Web API references<br />

I will use this project to create a regular MVC Framework application and then use the Web API to create a web service. Once<br />

the web service is complete, I’ll return to the MVC Framework application and make it into a single-page application.<br />

Creating the Model<br />

This application will create and maintain a series of reservations. I want to keep the application simple so that I can focus on the<br />

mechanics of the features I describe, and so these reservations will consist of just a name and a location. I added a class file called<br />

Reservation.cs to the Models folder, the contents of which are shown in Listing 27-1.<br />

Listing 27-1. The Contents of the Reservation.cs File<br />

namespace WebServices.Models {<br />

public class Reservation {<br />

public int ReservationId { get; set; }<br />

public string ClientName { get; set; }<br />

public string Location { get; set; }<br />

}<br />

}<br />

I am going to create a simple in-memory collection of Reservation objects to act as the model repository. I don’t want<br />

to go to the trouble of setting up a database, but I do need to be able to perform CRUD operations on a collection of model objects<br />

so that I can demonstrate some important aspects of the Web API. I added a class file called<br />

705

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!