/// <summary> /// "Done" function. Should be called when the user attempts to finish creating/editing /// a RepeatingAlarm. /// /// If everything looks good, this will publish through the event aggregator either an /// EditAlarmEvent or a NewAlarmEvent (depending on create/edit mode). /// /// Sends either a SuccessEvent on a success or a NoRepeatError in the case that this /// was called, but the Alarm created had no repeats set. /// </summary> private void Done() { RepeatingAlarm alarm = new RepeatingAlarm(); setAlarmRepeats(alarm); if (alarm.HasRepeats()) { if (_isEditMode) { EditAlarmWrapper wrapper = new EditAlarmWrapper(_oldAlarm, alarm); _eventAggregator.GetEvent <EditAlarmEvent>().Publish(wrapper); } else { _eventAggregator.GetEvent <NewAlarmEvent>().Publish(alarm); } // All done, fire success event if (SuccessEvent != null) { this.SuccessEvent(this, EventArgs.Empty); } } else { // No repeats were set; fire error event if (NoRepeatError != null) { this.NoRepeatError(this, EventArgs.Empty); } } }
/// <summary> /// "Done" button functionality. /// /// Parses the various fields in use by the ViewModel into a TimeSpan, and creates an /// Alarm with the given time. Then, publishes either an EditAlarmEvent or a NewAlarmEvent, /// depending on mode. /// </summary> private void Done() { int mins = (MinTens * 10) + MinOnes; int hour = Hour % 12; hour = (IsPm) ? (hour + 12) : hour; hour = (hour == 24) ? 0 : hour; TimeSpan alarmTime = new TimeSpan(hour, mins, 0); BasicAlarm alarm = new BasicAlarm(alarmTime); if (_isEditMode) { EditAlarmWrapper wrapper = new EditAlarmWrapper(_oldAlarm, alarm); _eventAggregator.GetEvent <EditAlarmEvent>().Publish(wrapper); } else { _eventAggregator.GetEvent <NewAlarmEvent>().Publish(alarm); } }