コード例 #1
0
 //insert customer
 public HttpResponseMessage Post(BookingModel customer)
 {
     if (ModelState.IsValid)
     {
         db.AddBooking(customer);
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, customer);
         response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = customer.BookingID }));
         return response;
     }
     else
     {
         return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
     }
 }
コード例 #2
0
 //update customer
 public HttpResponseMessage Put(int id, BookingModel customer)
 {
     if (!ModelState.IsValid)
     {
         return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
     }
     if (id != customer.BookingID)
     {
         return Request.CreateResponse(HttpStatusCode.BadRequest);
     }
     try
     {
         db.EditBooking(customer);
     }
     catch (DbUpdateConcurrencyException ex)
     {
         return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex);
     }
     return Request.CreateResponse(HttpStatusCode.OK);
 }