public async Task<IHttpActionResult> PostAgent(Agent agent) { if (!ModelState.IsValid) { return BadRequest(ModelState); } agent.AgentId = Guid.NewGuid(); db.Agents.Add(agent); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (AgentExists(agent.AgentId)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = agent.AgentId }, agent); }
public async Task<IHttpActionResult> PutAgent(Guid id, Agent agent) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != agent.AgentId) { return BadRequest(); } db.Entry(agent).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AgentExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }