public async Task<IHttpActionResult> PutTopic(int id, Topic topic) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != topic.TopicId) { return BadRequest(); } db.Entry(topic).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TopicExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostTopic(Topic topic) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Topics.Add(topic); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (TopicExists(topic.TopicId)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = topic.TopicId }, topic); }