Beispiel #1
0
        public DefaultMessageSettingViewModel(IEnumerable <IAutoAnswer> answers)
        {
            Answers  = answers;
            Settings = answers.Select(x => new SettingInfo {
                Name = x.Name, Key = x.SettingKey
            }).ToList();
            Items        = OrmManager.Fetch <QQState>(x => x.Id > 0);
            SavedCommand = new Command(() => {
                foreach (var setting in Settings)
                {
                    SelectedItem.SetState(setting.Key, setting.Selected);
                }
                OrmManager.Update(SelectedItem);
                var client = SelectedItem.GetClient();
                if (client != null)
                {
                    client.DefaultState = SelectedItem.State;
                }
            });
            SelectedCommand = new Command(() => {
                if (string.IsNullOrEmpty(SelectedItem.State))
                {
                    SelectedItem.State = "{}";
                }
                for (int i = 0; i < Settings.Count; i++)
                {
                    Settings[i].Selected = SelectedItem.GetState <bool>(Settings[i].Key);
                }

                RaisePropertyChanged(nameof(Settings));
                PrevSelectedItem = SelectedItem;
            }, () => SelectedItem != PrevSelectedItem && SelectedItem != null);
        }