public async Task<IHttpActionResult> PutWorker(int id, Worker worker) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != worker.Id) { return BadRequest(); } db.Entry(worker).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WorkerExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostWorker(Worker worker) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Workers.Add(worker); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = worker.Id }, worker); }