public IHttpActionResult PostTriviaOption(TriviaOption triviaOption) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.TriviaOptions.Add(triviaOption); try { db.SaveChanges(); } catch (DbUpdateException) { if (TriviaOptionExists(triviaOption.QuestionId)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = triviaOption.QuestionId }, triviaOption); }
public IHttpActionResult PutTriviaOption(int id, TriviaOption triviaOption) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != triviaOption.QuestionId) { return BadRequest(); } db.Entry(triviaOption).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TriviaOptionExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }