public async Task<IHttpActionResult> PutCoffee(int id, Coffee coffee) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != coffee.Id) { return BadRequest(); } db.Entry(coffee).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CoffeeExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostCoffee(Coffee coffee) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Coffees.Add(coffee); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = coffee.Id }, coffee); }