public IHttpActionResult PutSmartphone(int id, Smartphone smartphone) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != smartphone.Id) { return BadRequest(); } db.Entry(smartphone).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!SmartphoneExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostSmartphone(Smartphone smartphone) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Smartphones.Add(smartphone); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = smartphone.Id }, smartphone); }