public IHttpActionResult PostConsumable(Consumable consumable) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Consumables.Add(consumable); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = consumable.Id }, consumable); }
public IHttpActionResult PutConsumable(int id, Consumable consumable) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != consumable.Id) { return BadRequest(); } db.Entry(consumable).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ConsumableExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }