public DatabaseExpItemVM(AccountExpItemVM parentAccount, DatabaseModel model, MainVM main) : base(main) { _model = model; this.Children.Add(new DummyExpItemVM(main)); this.ContextMenuItems.Add(new MenuItemVM() { Caption = "Refresh", Command = new LambdaCommand(async (o) => { await refresh(); }) }); this.ContextMenuItems.Add(new MenuItemVM() { Caption = "Create collection", Command = new LambdaCommand(async (o) => { var dlg = new NameSelector("New collection name"); if (dlg.ShowDialog() == true && dlg.Value.IsNotEmpty()) { var created = await _model.CreateCollection(dlg.Value); this.Children.Insert(0, new CollectionExpItemVM(this, created, main)); } }) }); this.ContextMenuItems.Add(new MenuItemVM() { Caption = "Delete database", Command = new LambdaCommand(async (o) => { MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { await this._model.DeleteDabaseFormAccount(); parentAccount.Children.Remove(this); } }) }); }
public AccountExpItemVM(AccountModel model, MainVM main) : base(main) { IsBroken = false; _model = model; this.Children.Add(new DummyExpItemVM(main)); this.ContextMenuItems.Add(new MenuItemVM() { Caption = "Refresh", Command = new LambdaCommand(async (o) => { await this.LoadDatabases(); }) }); this.ContextMenuItems.Add(new MenuItemVM() { Caption = "Create database", Command = new LambdaCommand(async (o) => { if(IsBroken) { MessageBox.Show("Can't create database on a broken connect, check error message, try to reenter credentials."); return; } var dlg = new NameSelector("New database name"); if (dlg.ShowDialog() == true && dlg.Value.IsNotEmpty()) { var created = await _model.CreateDatabase(dlg.Value); this.Children.Insert(0,new DatabaseExpItemVM(this, created, this.Main)); } }) }); this.ContextMenuItems.Add(new MenuItemVM() { Caption = "Change access data", Command = new LambdaCommand((o) => { var oldEndpoint = _model.Endpoint; DocDbAccountCredentialsDlg.ShowDialog(_model.Credentials, async (creds) => { await performWithIsBrokenTest(async () => { this.Children.Clear(); await _model.RefreshCredentials(); foreach (var db in this._model.Databases) { this.Children.Add(new DatabaseExpItemVM(this, db, this.Main)); } Config.Instance.ChangeAccountCredentials(oldEndpoint, _model.Credentials); }); }); }) }); this.ContextMenuItems.Add(new MenuItemVM() { Caption = "Remove", Command = new LambdaCommand((o) => { MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Removal Confirmation", System.Windows.MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { main.Explorer.RootItems.Remove(this); Config.Instance.RemoveAccount(_model.Endpoint); } }) }); }