public AdminViewModel() { Navigation.New = new AwaitableDelegateCommand(() => ConfirmCancelLocker.LockForDurationAsync(NewCallback), () => NewEnableCallback(NewEnable())); Navigation.Duplicate = new AwaitableDelegateCommand(() => ConfirmCancelLocker.LockForDurationAsync(DuplicateCallback), () => DuplicateEnableCallback(DuplicateEnable())); Navigation.Modify = new AwaitableDelegateCommand(() => ConfirmCancelLocker.LockForDurationAsync(ModifyCallback), () => ModifyEnableCallback(ModifyEnable())); Navigation.ReloadCurrent = new AwaitableDelegateCommand(() => RefreshModelInformation(Model.Id), () => ReloadCurrentEnable()); Navigation.Confirm = new AwaitableDelegateCommand(() => ConfirmCancelLocker.LockForDurationAsync(ConfirmCallback), () => ConfirmEnable()); Navigation.Cancel = new AwaitableDelegateCommand(() => ConfirmCancelLocker.LockForDurationAsync(CancelCallback), () => CancelEnable()); Model.ErrorsChanged += Model_ErrorsChanged; _backForwardNavigator = new ExtendedNavigator <int>(); SetUpNewNavigator(); ConfirmCancelLocker.LockStatusChanged += (s, e) => { Navigation.New.RaiseCanExecuteChanged(); Navigation.Duplicate.RaiseCanExecuteChanged(); Navigation.Modify.RaiseCanExecuteChanged(); Navigation.Confirm.RaiseCanExecuteChanged(); Navigation.Cancel.RaiseCanExecuteChanged(); }; NewRecordCancelLocker.LockStatusChanged += (s, e) => { Navigation.Confirm.RaiseCanExecuteChanged(); Navigation.Cancel.RaiseCanExecuteChanged(); }; OutsideModificationLocker.RequestLock(_modifyingToken); OutsideModificationLocker.LockStatusChanged += (s, e) => OnPropertyChanged(nameof(OutsideModificationAllowed)); }
/// <summary> /// Used to dispose of resources in use by the <see cref="AdminViewModel{TViewModel, TModel, TModelSearcher}"/> /// </summary> /// <param name="disposing"></param> protected override void Dispose(bool disposing) { if (!_disposedValue) { if (disposing) { ApplicationRestrictor.RequestUnlock(_adminToken); FamilialLocker.RequestUnlock(_adminToken); CriticalOperationType = CriticalOperationType.None; if (ModelSearcher != null) { ModelSearcher.SelectedItems.CollectionChanged -= SelectedItems_CollectionChanged; ModelSearcher.ExportId -= ModelSearcher_ExportId; ModelSearcher.Cleared -= ModelSearcher_Cleared; ModelSearcher.RequestEnable(_adminToken); } Model.ErrorsChanged -= Model_ErrorsChanged; Model.Dispose(); _newEnableCallback = null; _duplicateEnableCallback = null; _modifyEnableCallback = null; _backEnableCallback = null; _forwardEnableCallback = null; _performDeleteOnRecordEnableCallback = null; _backForwardNavigator.CurrentItemChangedCallback = null; _backForwardNavigator?.Dispose(); Navigation.Dispose(); RecordChangeLocker.Dispose(); ConfirmCancelLocker.Dispose(); NewRecordCancelLocker.Dispose(); NavigationalOverride.Dispose(); OutsideModificationLocker.Dispose(); DefaultModelCallback = null; Locators.ForEach(locator => { locator.SearchToBegin -= Locator_SearchToBegin; locator.SearchComplete -= Locator_SearchComplete; locator.RecordRequested -= Locator_RecordRequested; locator.RequestEnable(_adminToken); }); Locators.Clear(); } _disposedValue = true; } base.Dispose(disposing); }
/// <summary> /// The default enable for the Confirm Command. /// </summary> /// <returns>True enables button. False is a disable.</returns> protected virtual bool ConfirmEnable() => HasErrors == false && Modifying && ConfirmCancelLocker.IsFree() && NavigationalOverride.IsFree();
/// <summary> /// The default enable for the Cancel Command. /// </summary> /// <returns>True enables button. False is a disable.</returns> protected virtual bool CancelEnable() => Modifying && ConfirmCancelLocker.IsFree() && (NewRecordCancelLocker.IsFree() || CriticalOperationType != CriticalOperationType.AddingNewRecord) && NavigationalOverride.IsFree();