Database Reference
In-Depth Information
// iterate through child entities, assigning correct state.
foreach (var booking in travelAgent.Bookings)
{
if (booking.BookingId > 0)
// assume booking already exists if ID is greater than zero.
// set entity to be updated.
context.Entry(booking).State = EntityState.Modified;
}
context.SaveChanges();
HttpResponseMessage response;
// set Http Status code based on operation type
response = Request.CreateResponse(newParentEntity
? HttpStatusCode.Created : HttpStatusCode.OK, travelAgent);
return response;
}
}
[HttpDelete]
public HttpResponseMessage Cleanup()
{
using (var context = new Recipe3Context())
{
context.Database.ExecuteSqlCommand("delete from chapter9.booking");
context.Database.ExecuteSqlCommand("delete from chapter9.travelagent");
}
return Request.CreateResponse(HttpStatusCode.OK);
}
}
Next we create the client Visual Studio solution that will consume the Web API service.
10.
Create a new Visual Studio solution that contains a Console application entitled
Recipe3.Client .
11.
Replace the code in the program.cs file with that from Listing 9-18.
Listing 9-18. Our Windows Console Application That Serves as Our Test Client
internal class Program
{
private HttpClient _client;
private TravelAgent _agent1, _agent2;
private Booking _booking1, _booking2, _booking3;
private HttpResponseMessage _response;
 
Search WWH ::




Custom Search