Inheritance: ExplorerItemBaseVM
        public void AddAsView(string viewName)
        {
            var newView = this.View.Clone();

            newView.ViewName = viewName;

            if (!this.IsView)
            {
                var newItem = new CollectionExpItemVM(_parentDbExpItem, _model, Main, newView, this);
                this.Children.Add(newItem);
                this.IsExpanded    = true;
                newItem.IsSelected = true;
                Config.Instance.AddCollectionView(_model.AccountEndpoint, _model.DatabaseName, newView);
                this._wrkspc.Collection.Reset();
            }
            else
            {
                var newItem = new CollectionExpItemVM(_parentDbExpItem, _model, Main, newView, this.ViewSourceCollection);
                this.ViewSourceCollection.Children.Add(newItem);
                this.ViewSourceCollection.IsExpanded = true;
                newItem.IsSelected = true;
                Config.Instance.AddCollectionView(_model.AccountEndpoint, _model.DatabaseName, newView);
            }
            Config.Instance.ResetSelectedCollection();
        }
        public void AddAsView(string viewName)
        {
            var newView = this.View.Clone();
            newView.ViewName = viewName;

            if (!this.IsView)
            {
                var newItem = new CollectionExpItemVM(_parentDbExpItem, _model, Main, newView, this);
                this.Children.Add(newItem);
                this.IsExpanded = true;
                newItem.IsSelected = true;
                Config.Instance.AddCollectionView(_model.AccountEndpoint, _model.DatabaseName, newView);
                this._wrkspc.Collection.Reset();
            }
            else
            {
                var newItem = new CollectionExpItemVM(_parentDbExpItem, _model, Main, newView, this.ViewSourceCollection);
                this.ViewSourceCollection.Children.Add(newItem);
                this.ViewSourceCollection.IsExpanded = true;
                newItem.IsSelected = true;
                Config.Instance.AddCollectionView(_model.AccountEndpoint, _model.DatabaseName, newView);
            }
            Config.Instance.ResetSelectedCollection();
        }
        public CollectionExpItemVM(DatabaseExpItemVM parentDatabaseExp, CollectionModel model, MainVM main, CollectionViewModel sourceView = null, CollectionExpItemVM viewSourceCollection = null) : base(main)
        {
            _parentDbExpItem = parentDatabaseExp;
            _model = model;
            if (sourceView != null)
            {
                this.View = sourceView;
                IsView = true;
                ViewSourceCollection = viewSourceCollection;
            }
            else
            {
                this.View = new CollectionViewModel();
                IsView = false;
            }
            this.ContextMenuItems.Add(new MenuItemVM()
            {
                Caption = "Refresh",
                Command = new LambdaCommand((o) => _wrkspc?.Refresh())
            });
           

            if (sourceView == null)
            {
                var savedCollection = Config.Instance.GetCollection(model.AccountEndpoint, model.DatabaseName, model.Name);
                if (savedCollection != null)
                {
                    this.IsExpanded = savedCollection.IsExpanded;
                    if (savedCollection.Views != null)
                    {
                        foreach (var view in savedCollection.Views)
                        {
                            this.Children.Add(new CollectionExpItemVM(parentDatabaseExp, model, main, view, this));
                        }
                    }
                }
                this.ContextMenuItems.Add(new MenuItemVM()
                {
                    Caption = "Delete collection",
                    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.DeleteCollectionFromDatabase();
                            parentDatabaseExp.Children.Remove(this);
                        }
                    })
                });
            }
            else
            {
                this.ContextMenuItems.Add(new MenuItemVM()
                {
                    Caption = "Delete view",
                    Command = new LambdaCommand((o) =>
                    {
                        MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);
                        if (messageBoxResult == MessageBoxResult.Yes)
                        {
                            this.ViewSourceCollection.Children.Remove(this);
                            this.ViewSourceCollection.IsSelected = true;
                            Config.Instance.RemoveCollectionView(_model.AccountEndpoint, _model.DatabaseName, this.View);
                        }
                    })
                });
            }
        }
 public CollectionWrkspcVM(CollectionModel model, CollectionExpItemVM expItem): base()
 {
     _model = model;
     ExpItem = expItem;
     this.Collection = new CollectionVM(model, this);
     
 }
        public CollectionExpItemVM(DatabaseExpItemVM parentDatabaseExp, CollectionModel model, MainVM main, CollectionViewModel sourceView = null, CollectionExpItemVM viewSourceCollection = null) : base(main)
        {
            _parentDbExpItem = parentDatabaseExp;
            _model           = model;
            if (sourceView != null)
            {
                this.View            = sourceView;
                IsView               = true;
                ViewSourceCollection = viewSourceCollection;
            }
            else
            {
                this.View = new CollectionViewModel();
                IsView    = false;
            }
            this.ContextMenuItems.Add(new MenuItemVM()
            {
                Caption = "Refresh",
                Command = new LambdaCommand((o) => _wrkspc?.Refresh())
            });


            if (sourceView == null)
            {
                var savedCollection = Config.Instance.GetCollection(model.AccountEndpoint, model.DatabaseName, model.Name);
                if (savedCollection != null)
                {
                    this.IsExpanded = savedCollection.IsExpanded;
                    if (savedCollection.Views != null)
                    {
                        foreach (var view in savedCollection.Views)
                        {
                            this.Children.Add(new CollectionExpItemVM(parentDatabaseExp, model, main, view, this));
                        }
                    }
                }
                this.ContextMenuItems.Add(new MenuItemVM()
                {
                    Caption = "Delete collection",
                    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.DeleteCollectionFromDatabase();
                            parentDatabaseExp.Children.Remove(this);
                        }
                    })
                });
            }
            else
            {
                this.ContextMenuItems.Add(new MenuItemVM()
                {
                    Caption = "Delete view",
                    Command = new LambdaCommand((o) =>
                    {
                        MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);
                        if (messageBoxResult == MessageBoxResult.Yes)
                        {
                            this.ViewSourceCollection.Children.Remove(this);
                            this.ViewSourceCollection.IsSelected = true;
                            Config.Instance.RemoveCollectionView(_model.AccountEndpoint, _model.DatabaseName, this.View);
                        }
                    })
                });
            }
        }