public IHttpActionResult PutPerson(int id, Person person) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != person.Id) { return(BadRequest()); } db.Entry(person).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PersonExists(id)) { return(NotFound()); } else { throw; } } return(Ok(person)); }
// DELETE: api/Trips/5 public IHttpActionResult Delete(int id) { using (var context = new LocatorEntities()) { var foundTrip = context.Trips.FirstOrDefault(c => c.Id == id); context.Trips.Remove(foundTrip); context.SaveChanges(); return(Ok(foundTrip)); } }
// POST: api/Trips public IHttpActionResult Post(Trip newTrip) { using (var context = new LocatorEntities()) { newTrip.Created = DateTime.Now.ToString(); context.Trips.Add(newTrip); context.SaveChanges(); return(Ok(newTrip)); } }
// PUT: api/Trips/5 public IHttpActionResult Put(int id, Trip trip) { using (var context = new LocatorEntities()) { var foundTrip = context.Trips.FirstOrDefault(c => c.Id == id); foundTrip.Name = trip.Name; foundTrip.Created = trip.Created; context.SaveChanges(); return(Ok(foundTrip)); } }