public async Task<IHttpActionResult> PutDepartment(int id, Department department) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != department.Id) { return BadRequest(); } db.Entry(department).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DepartmentExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostDepartment(Department department) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Departments.Add(department); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = department.Id }, department); }