public IHttpActionResult PutTone(long id, Tone tone) { string uid = User.Identity.GetUserId(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tone.Id) { return(BadRequest()); } var existingtone = db.Tones.Find(id); if (tone.UserId != uid) { return(BadRequest()); } tone.UserId = uid; db.Entry(tone).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ToneExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutAlarm(long id, Alarm alarm) { string uid = User.Identity.GetUserId(); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != alarm.Id) { return(BadRequest()); } var al = db.Alarms.Find(id); if (al == null || al.UserId != uid) { return(BadRequest()); } alarm.UserId = uid; db.Entry(alarm).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AlarmExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public IHttpActionResult PutClockSettings(ClockSettings clockSettings) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } clockSettings.UserId = User.Identity.GetUserId(); clockSettings.ScheduleId = clockSettings.Schedule.Id; db.Entry(clockSettings).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { throw; } return(StatusCode(HttpStatusCode.NoContent)); }