// PUT: odata/CandidatesApi(5) public async Task<IHttpActionResult> Put([FromODataUri] int key, Candidate candidate) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (key != candidate.ID) { return BadRequest(); } db.Entry(candidate).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CandidateExists(key)) { return NotFound(); } else { throw; } } return Updated(candidate); }
// POST: odata/CandidatesApi public async Task<IHttpActionResult> Post(Candidate candidate) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Candidates.Add(candidate); await db.SaveChangesAsync(); return Created(candidate); }