public async Task<IHttpActionResult> PostAuto(Auto auto) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Autos.Add(auto); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (AutoExists(auto.Id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = auto.Id }, auto); }
public async Task<IHttpActionResult> PutAuto(Guid id, Auto auto) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != auto.Id) { return BadRequest(); } db.Entry(auto).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AutoExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }