// POST api/Attractions public IHttpActionResult PostTouristAttraction(TouristAttraction touristattraction) { if (ModelState.IsValid) { db.TouristAttractions.Add(touristattraction); db.SaveChanges(); Uri location = new Uri(Url.Link("DefaultApi", new { id = touristattraction.TouristAttractionId })); return Created(location, touristattraction); } else { return BadRequest(); } }
// POST api/Attractions public HttpResponseMessage PostTouristAttraction(TouristAttraction touristattraction) { if (ModelState.IsValid) { db.TouristAttractions.Add(touristattraction); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, touristattraction); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = touristattraction.TouristAttractionId })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// PUT api/Attractions/5 public IHttpActionResult PutTouristAttraction(int id, TouristAttraction touristattraction) { if (ModelState.IsValid && id == touristattraction.TouristAttractionId) { db.Entry(touristattraction).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return NotFound(); } return Ok(); } else { return BadRequest(); } }
// PUT api/Attractions/5 public HttpResponseMessage PutTouristAttraction(int id, TouristAttraction touristattraction) { if (ModelState.IsValid && id == touristattraction.TouristAttractionId) { db.Entry(touristattraction).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }