public async Task<IHttpActionResult> PutDevice(string id, Device device) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != device.id) { return BadRequest(); } db.Entry(device).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!DeviceExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
//Populates the Device table private void PopulateDevice() { Device htc = new Device() { id = "HT451WM08832", deviceType = "android", token = "fMXJqM0z0FQ:APA91bHHp_TLeg3Z3ES3qc1Kdt25KUFdX5G5gZLgVqrdjSA3uQZkmuR9V-b78X48T9ZGCGJkdyqvBeFrpoYyCbgnw5_7dslTjbR4E9SEm74uh-e4pOqeJjcrA5smhcQUuP_YQoNwVNvY" }; db.devices.Add(htc); db.SaveChanges(); }
public async Task<IHttpActionResult> PostDevice(Device device) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.devices.Add(device); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (DeviceExists(device.id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = device.id }, device); }