Inheritance: Zetbox.Client.Presentables.ViewModel
Beispiel #1
0
        protected void UpdateViewModel(string name, SavedListConfig item)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (_configs != null)
            {
                SavedListConfigViewModel vmdl = this._configs.Rw.SingleOrDefault(i => i.Object.Name == name && i.IsMyOwn);
                if (vmdl == null)
                {
                    vmdl = ViewModelFactory.CreateViewModel <SavedListConfigViewModel.Factory>().Invoke(DataContext, this, item, true);
                    _configs.Rw.Add(vmdl);
                    SelectedItem = vmdl;
                }
                else
                {
                    vmdl.Object = item;
                }
            }
        }
Beispiel #2
0
        public void Rename(SavedListConfigViewModel itemToRename)
        {
            if (itemToRename == null)
            {
                throw new ArgumentNullException("itemToRename");
            }

            string newName = null;
            string oldName = itemToRename.Name;

            ViewModelFactory.CreateDialog(SavedListConfiguratorViewModelResources.SaveDlgTitle)
            .AddString(SavedListConfiguratorViewModelResources.SaveDlgNameLabel)
            .Show((p) => { newName = p[0] as string; });
            if (string.IsNullOrEmpty(newName))
            {
                return;
            }

            using (var ctx = ctxFactory())
            {
                var config = GetSavedConfig(ctx);
                var obj    = ExtractConfigurationObject(config);
                var item   = obj.Configs.FirstOrDefault(i => i.Name == oldName);
                if (item != null)
                {
                    item.Name            = newName;
                    config.Configuration = obj.ToXmlString();
                    ctx.SubmitChanges();
                    UpdateViewModel(oldName, item);
                }
            }
        }
Beispiel #3
0
 protected void RemoveViewModel(string name)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException("name");
     }
     if (_configs != null)
     {
         SavedListConfigViewModel vmdl = this._configs.Rw.SingleOrDefault(i => i.Object.Name == name && i.IsMyOwn);
         if (vmdl != null)
         {
             _configs.Rw.Remove(vmdl);
             SelectedItem = null;
         }
     }
 }
Beispiel #4
0
        public void Delete(SavedListConfigViewModel itemToDelete)
        {
            if (itemToDelete == null)
            {
                throw new ArgumentNullException("itemToDelete");
            }
            if (ViewModelFactory.GetDecisionFromUser(string.Format(SavedListConfiguratorViewModelResources.DeleteMessage, itemToDelete.Name), SavedListConfiguratorViewModelResources.DeleteTitle) == true)
            {
                using (var ctx = ctxFactory())
                {
                    var config = GetSavedConfig(ctx);
                    var obj    = ExtractConfigurationObject(config);

                    var item = obj.Configs.FirstOrDefault(i => i.Name == itemToDelete.Name);
                    if (item != null)
                    {
                        obj.Configs.Remove(item);
                        config.Configuration = obj.ToXmlString();
                        ctx.SubmitChanges();
                        RemoveViewModel(item.Name);
                    }
                }
            }
        }
        protected void UpdateViewModel(string name, SavedListConfig item)
        {
            if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name");
            if (item == null) throw new ArgumentNullException("item");

            var configs = EnsureConfigsTask().Get();
            if (configs != null)
            {
                SavedListConfigViewModel vmdl = configs.Rw.SingleOrDefault(i => i.Object.Name == name && i.IsMyOwn);
                if (vmdl == null)
                {
                    vmdl = ViewModelFactory.CreateViewModel<SavedListConfigViewModel.Factory>().Invoke(DataContext, this, item, true);
                    configs.Rw.Add(vmdl);
                    SelectedItem = vmdl;
                }
                else
                {
                    vmdl.Object = item;
                }
            }
        }
        protected void RemoveViewModel(string name)
        {
            if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name");
            var configs = EnsureConfigsTask().Get();

            if (configs != null)
            {
                SavedListConfigViewModel vmdl = configs.Rw.SingleOrDefault(i => i.Object.Name == name && i.IsMyOwn);
                if (vmdl != null)
                {
                    configs.Rw.Remove(vmdl);
                    SelectedItem = null;
                }
            }
        }
 public void Reset()
 {
     SelectedItem = null;
     Parent.ResetSort(refresh: false);
     Parent.FilterList.ResetUserFilter();
     Parent.ResetDisplayedColumns();
 }
        public void Rename(SavedListConfigViewModel itemToRename)
        {
            if (itemToRename == null) throw new ArgumentNullException("itemToRename");

            string newName = null;
            string oldName = itemToRename.Name;

            ViewModelFactory.CreateDialog(DataContext, SavedListConfiguratorViewModelResources.SaveDlgTitle)
                .AddString("name", SavedListConfiguratorViewModelResources.SaveDlgNameLabel)
                .Show(p => { newName = p["name"] as string; });
            if (string.IsNullOrEmpty(newName)) return;

            using (var ctx = ViewModelFactory.CreateNewContext())
            {
                var config = GetSavedConfig(ctx);
                var obj = ExtractConfigurationObject(config);
                var item = obj.Configs.FirstOrDefault(i => i.Name == oldName);
                if (item != null)
                {
                    item.Name = newName;
                    config.Configuration = obj.ToXmlString();
                    ctx.SubmitChanges();
                    UpdateViewModel(oldName, item);
                }
            }
        }
        public void Delete(SavedListConfigViewModel itemToDelete)
        {
            if (itemToDelete == null) throw new ArgumentNullException("itemToDelete");
            if (ViewModelFactory.GetDecisionFromUser(string.Format(SavedListConfiguratorViewModelResources.DeleteMessage, itemToDelete.Name), SavedListConfiguratorViewModelResources.DeleteTitle) == true)
            {
                using (var ctx = ViewModelFactory.CreateNewContext())
                {
                    var config = GetSavedConfig(ctx);
                    var obj = ExtractConfigurationObject(config);

                    var item = obj.Configs.FirstOrDefault(i => i.Name == itemToDelete.Name);
                    if (item != null)
                    {
                        obj.Configs.Remove(item);
                        config.Configuration = obj.ToXmlString();
                        ctx.SubmitChanges();
                        RemoveViewModel(item.Name);
                    }
                }
            }
        }