public 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 { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DepartmentExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostDepartment(Department department) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Departments.Add(department); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = department.Id }, department); }