public IHttpActionResult PutSchedule(long id, Schedule schedule)
      {
          string uid = User.Identity.GetUserId();

          if (!ModelState.IsValid)
          {
              return(BadRequest(ModelState));
          }
          var sch = db.Schedules.Find(id);

          if (sch == null || sch.UserId != uid)
          {
              return(NotFound());
          }
          if (id != schedule.Id)
          {
              return(BadRequest());
          }


          sch.Description = schedule.Description;
          schedule.Name   = sch.Name;
          schedule.UserId = uid;
          foreach (var child in schedule.Alarms)
          {
              var alarm = db.Alarms.Find(child.Id);
              alarm.Note   = child.Note;
              alarm.Time   = child.Time;
              alarm.ToneId = child.ToneId;

              alarm.UserId = uid;
          }


          try
          {
              db.SaveChanges();
          }
          catch (DbUpdateConcurrencyException)
          {
              if (!ScheduleExists(id))
              {
                  return(NotFound());
              }
              else
              {
                  throw;
              }
          }

          return(StatusCode(HttpStatusCode.NoContent));
      }
        private void SetDefaultSchedule(ApplicationUser user)
        {
            string uid       = user.Id;
            var    dbcontext = new AlarmClockEntities();

            var schedule = new Schedule {
                Name = "Sample Schedule", Description = "Sample schedule for testing purposes", UserId = uid, Alarms = new List <Alarm> {
                    new Alarm {
                        Note = "Sample Note", Time = "13:00", Tone = new Tone {
                            FileName = "Musics/SampleTone.mp3", Name = "SampleTone", UserId = uid
                        }, UserId = uid
                    }
                }
            };
            var clocksettings = dbcontext.ClockSettings.SingleOrDefault(c => c.UserId == uid);

            if (clocksettings != null)
            {
                clocksettings.Schedule = schedule;
            }
            else
            {
                dbcontext.ClockSettings.Add(new ClockSettings {
                    UserId = uid, Schedule = schedule
                });
            }
            dbcontext.Schedules.Add(schedule);
            dbcontext.SaveChanges();
        }
Ejemplo n.º 3
0
        public IHttpActionResult GetClockSettings()
        {
            //   db.Configuration.ProxyCreationEnabled = false;
            string        uid           = User.Identity.GetUserId();
            ClockSettings clockSettings = db.ClockSettings.SingleOrDefault(z => z.UserId == uid);

            if (clockSettings == null)
            {
                var cs = new ClockSettings {
                    UserId = uid
                };
                db.ClockSettings.Add(cs);
                db.SaveChanges();
            }

            return(Ok(db.ClockSettings.SingleOrDefault(z => z.UserId == uid)));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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));
        }