public async Task<IHttpActionResult> PutRoute(int id, Route route) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != route.Id) { return BadRequest(); } _database.Entry(route).State = EntityState.Modified; try { await _database.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RouteExists(id)) { return NotFound(); } // else! throw; } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostRoute(Route route) { if (!ModelState.IsValid) { return BadRequest(ModelState); } _database.Routes.Add(route); await _database.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = route.Id }, route); }