private void CalculateNextActivation(ref PresetActivation presetActivation) { if (!presetActivation.Active[0]) { presetActivation.NextActivationTime = DateTime.MaxValue; } var res = DateTime.Today; res += presetActivation.ActivationTime; var currentWeekday = res.DayOfWeek; for (int i = 1; i <= 8; i++) { if (i == 8) { res = res.AddDays(1); presetActivation.Active[0] = false; break; } var index = i + (int)currentWeekday; if (index >= 7) { index -= 7; } if (presetActivation.DaysOfWeek[index]) { res = res.AddDays(i); break; } } presetActivation.NextActivationTime = res; }
public ActionResult Update(PresetActivationModel model) { var pa = new PresetActivation { Id = model.Id, ActivationTime = model.ActivationTime, Active = new BitArray(new [] { model.Active }), DaysOfWeek = new BitArray(new [] { model.Sunday, model.Monday, model.Tuesday, model.Wednesday, model.Thursday, model.Friday, model.Saturday }) }; ledController.SavePresetActivation(pa, model.SelectedPreset); return(RedirectToAction("Index")); }
public PresetActivationModel(PresetActivation x, string[] allPresets) { Id = x.Id; ActivationTime = x.ActivationTime; AllPresets = allPresets; SelectedPreset = x.Preset.Name; Active = x.Active[0]; Sunday = x.DaysOfWeek[(int)DayOfWeek.Sunday]; Monday = x.DaysOfWeek[(int)DayOfWeek.Monday]; Tuesday = x.DaysOfWeek[(int)DayOfWeek.Thursday]; Wednesday = x.DaysOfWeek[(int)DayOfWeek.Wednesday]; Thursday = x.DaysOfWeek[(int)DayOfWeek.Thursday]; Friday = x.DaysOfWeek[(int)DayOfWeek.Friday]; Saturday = x.DaysOfWeek[(int)DayOfWeek.Saturday]; }
public void UpdatePresetActivation(PresetActivation presetActivation, string presetName) { using (var context = new PiHomeContext()) { var preset = context.LedPreset.Single(x => x.Name == presetName); var activation = context.PresetActivation.SingleOrDefault(x => x.Id == presetActivation.Id); if (activation == null) { presetActivation.Preset = preset; CalculateNextActivation(ref presetActivation); context.PresetActivation.Add(presetActivation); } else { activation.Preset = preset; activation.ActivationTime = presetActivation.ActivationTime; activation.Active = presetActivation.Active; activation.DaysOfWeek = presetActivation.DaysOfWeek; CalculateNextActivation(ref activation); } context.SaveChanges(); } }
public void SavePresetActivation(PresetActivation activation, string presetName) { repo.UpdatePresetActivation(activation, presetName); }