public IHttpActionResult PutNewUnit(int id, NewUnit newUnit) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != newUnit.Id) { return BadRequest(); } db.Entry(newUnit).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!NewUnitExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostNewUnit(NewUnit newUnit) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.NewUnits.Add(newUnit); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = newUnit.Id }, newUnit); }