/// <summary> /// Edit mode constructor /// </summary> /// <param name="alarm">Alarm to be edited.</param> /// <param name="eventAggregator">Event aggregator for the app</param> public SetAlarmPresenter(BasicAlarm alarm, IEventAggregator eventAggregator) { this._eventAggregator = eventAggregator; _isEditMode = true; _oldAlarm = alarm; int oldMins = _oldAlarm.time.Minute; _minTens = oldMins / 10; _minOnes = oldMins % 10; }
/// <summary> /// Opens the View for SetAlarm, either in New Alarm mode (default) or /// in Edit mode (if a BasicAlarm is passed). /// </summary> /// <param name="alarm">The alarm to edit. If null, then create a new alarm.</param> private void SetAlarmView(BasicAlarm alarm = null) { SetAlarm setAlarm; if (alarm == null) { // set new alarm setAlarm = new SetAlarm(); } else { // edit alarm setAlarm = new SetAlarm(alarm); } Main.Children.Add(setAlarm); }
/// <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); } }
/// <summary> /// Edit mode constructor /// </summary> /// <param name="editAlarm">The alarm to be edited.</param> public SetAlarm(BasicAlarm editAlarm) { this.DataContext = new SetAlarmPresenter(editAlarm, ApplicationService.Instance.EventAggregator); InitializeComponent(); }