public EventSelectorVM(IEnumerable <EventClassType> events, Action <IEnumerable <EventClassType> > onSave, Action onClose) { CloseCommand = new DelegateCommand( o => true, o => onClose() ); SaveCommand = new DelegateCommand( o => true, o => onSave(SelectedEvents.Select(x => x.EventClass)) ); AddEventCommand = new DelegateCommand( o => SelectedAvailableEvent != null, o => AddEvent(SelectedAvailableEvent) ); RemoveEventCommand = new DelegateCommand( o => SelectedSelectedEvent != null, o => RemoveEvent(SelectedSelectedEvent) ); ResetDefaultsCommand = new DelegateCommand( o => true, o => ResetDefaults() ); SetEvents(events); }
private void DoDeleteSelectedEvents(Confirmation confirmation) { if (!confirmation.Confirmed) { return; } _cmdGen.FireDeleteEvents(); Log.RemoveRange(SelectedEvents.Select(evm => evm.Event)); }
protected override void DeleteCore() { // Contains the same references as in SelectedEvents, // these references can change when un-doing so keep a snapshot around List <Event> previousSelection = new List <Event>(SelectedEvents); // Contains instance copies of events, this will be the old data before the do is applied. List <Event> eventsCopy = SelectedEvents.Select(d => d.DuckCopy <Event>()).ToList(); #region Do action Action doAction = delegate { // Get the view source of the events collection IEditableCollectionView eventsView = (IEditableCollectionView)EventsViewSource.View; foreach (Event calendarevent in SelectedEvents) { // Edit the view source eventsView.EditItem(calendarevent); // Move the event to the trash calendarevent.EventFolder = Folders.Trash; ClientState.Current.DataService.Update(calendarevent, "EventFolder"); // Let the world know that an event is moved to the trash EventBroker.Publish(AppEvents.UpdateEventState, calendarevent); // Commit the changes to the view eventsView.CommitEdit(); } }; #endregion #region Undo action Action undoAction = delegate { // Walk through all the events in the previous selection foreach (Event calendarevent in previousSelection) { // Get the origional event from the copied list var oldCalendarEvent = eventsCopy.Single(d => d.InternalEventId == calendarevent.InternalEventId); // Set the folder to the origional folder calendarevent.EventFolder = oldCalendarEvent.EventFolder; // Update the event ClientState.Current.DataService.Update(calendarevent, "EventFolder"); // Let the world know that an event is updated EventBroker.Publish(AppEvents.UpdateEventState, calendarevent); } // We cannot use the IEditableObject appraoch here because the document in question // probably might not be in view anymore. So instead we will refresh the whole view. EventsViewSource.View.Refresh(); }; #endregion // Add the do and undo actions to the UndoManager ClientState.Current.UndoManager.Execute(new HistoryAction(doAction, undoAction)); }