iWOWS/WolfOfWallStreet/ViewModels/SymbolsControllerViewModel.cs

55 lines
1.8 KiB
C#

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<Symbol> Symbols { get; set; } = new ObservableCollection<Symbol>();
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>(symbol =>
{
_settingsServices.RemoveSymbol(symbol);
Symbols.Remove(symbol);
});
}
}
}