using Prism.Commands; using Prism.Mvvm; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Windows.Input; using HandyControl.Controls; using WolfOfWallStreet.Models; using WolfOfWallStreet.Services; namespace WolfOfWallStreet.ViewModels { public class SymbolsControllerViewModel : ViewModelBase { private readonly SettingsServices _settingsServices; public ObservableCollection Symbols { get; set; } = new ObservableCollection(); public Symbol Symbol { get; set; } = new Symbol(); public ICommand AddSymbolCommand { get; set; } public ICommand RemoveSymbolCommand { get; set; } public SymbolsControllerViewModel(SettingsServices settingsServices) { _settingsServices = settingsServices; _settingsServices.GetSymbols().ForEach(s=>Symbols.Add(s)); } public override void InitialCommand() { base.InitialCommand(); AddSymbolCommand = new DelegateCommand((() => { try { if (string.IsNullOrEmpty(Symbol.symbolISIN)) throw new Exception("لطفا isin را وارد کنید"); if (string.IsNullOrEmpty(Symbol.SymbolName)) throw new Exception("لطفا نام سهم را وارد کنید"); _settingsServices.AddSymbol(Symbol); } catch (Exception e) { MessageBox.Show(e.Message); } })); RemoveSymbolCommand = new DelegateCommand(symbol => { _settingsServices.RemoveSymbol(symbol); Symbols.Remove(symbol); }); } } }