Пример #1
0
        private async void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            string   name     = TextBoxName.Text;
            TimeSpan time     = TimePickerTime.Time;
            bool     onlyOnce = ComboBoxRepeats.SelectedIndex == 0;

            var alarm = new MyAlarm()
            {
                Name      = name,
                TimeOfDay = time
            };

            if (onlyOnce)
            {
                if (time < DateTime.Now.TimeOfDay)
                {
                    // If time for today has already passed, set it for tomorrow
                    alarm.SingleFireTime = DateTime.Today.AddDays(1).Add(time);
                }
                else
                {
                    // Otherwise, set it for today at the time
                    alarm.SingleFireTime = DateTime.Today.Add(time);
                }
            }
            else
            {
                alarm.DaysOfWeek = new DayOfWeek[]
                {
                    DayOfWeek.Sunday,
                    DayOfWeek.Monday,
                    DayOfWeek.Tuesday,
                    DayOfWeek.Wednesday,
                    DayOfWeek.Thursday,
                    DayOfWeek.Friday,
                    DayOfWeek.Saturday
                };
            }

            await DataModel.AddAlarm(alarm);

            Frame.GoBack();
        }