public async Task<IHttpActionResult> PutChoice(int id, Choice choice) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != choice.ChoiceId) { return BadRequest(); } db.Entry(choice).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ChoiceExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostChoice(Choice choice) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Choices.Add(choice); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = choice.ChoiceId }, choice); }