public IHttpActionResult PutStation(int id, Station station) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != station.ID) { return BadRequest(); } db.Entry(station).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!StationExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostStation(Station station) { if (!ModelState.IsValid) { return BadRequest(ModelState); } //generate key and assign to a station String generatedKey = RandomString(32); station.Key = generatedKey; db.Stations.Add(station); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = station.ID }, station); }