private void SelectedInstrumentChanged(object o) { InstrumentViewModel instrument = o as InstrumentViewModel; InstrumentTypeViewModel instrumentType = o as InstrumentTypeViewModel; _logger.Debug($"{GetType().Name}.{MethodBase.GetCurrentMethod().Name} - {instrumentType?.Type} - {instrument?.DisplayName}"); if (instrument != null) { SelectedInstrument = instrument; // Console.WriteLine(instrument.DisplayName); } if (instrumentType != null) { SelectedInstrument = null; // Console.WriteLine(instrumentType.Type); } }
public InstrumentTypeViewModel GetInstrumentType(int id) { var instrumentType = this.DbContext .InstrumentTypes .Include(x => x.Instruments) .FirstOrDefault(x => x.Id == id); if (instrumentType == null) { return(null); } var instrumentTypeModel = new InstrumentTypeViewModel() { TypeName = instrumentType.TypeName, Instruments = this.Mapper.Map <ICollection <InstrumentConciseViewModel> >(instrumentType.Instruments) }; return(instrumentTypeModel); }
public InstrumentsWindowViewModel(ISettingsService settingsService, IMapper mapper, IExtendedLogger logger, IAccountsRequester accountsRequester) { _settingsService = settingsService; _logger = logger; _settings = settingsService.CachedSettings.SelectedEnvironment; _accountsRequester = accountsRequester; SelectedInstrumentChangedCommand = new RelayCommand <object>(SelectedInstrumentChanged); AddInstrumentToFavouritesContextCommand = new RelayCommand(AddInstrumentToFavourites); RemoveInstrumentToFavouritesContextCommand = new RelayCommand(RemoveInstrumentToFavourites); OpenInstrumentInMainContextCommand = new RelayCommand(OpenInstrumentInMain); OpenInstrumentInNewChartContextCommand = new RelayCommand(OpenInstrumentInNewChart); OpenInstrumentInTradeContextCommand = new RelayCommand(OpenInstrumentInTrade); if (IsInDesignMode) { } else { try { AccountInstrumentsResponse instrumentsResponse = _accountsRequester.GetAccountInstruments(_settings.DefaultAccountId); InstrumentCache.Instruments = instrumentsResponse.instruments; var allInstruments = mapper.Map <IList <InstrumentViewModel> >(InstrumentCache.Instruments); // todo automapper var groups = allInstruments.Select(x => x).GroupBy(x => x.Type).OrderBy(o => o.Key); List <InstrumentTypeViewModel> its = groups.Select(x => new InstrumentTypeViewModel { Type = x.Key, Instruments = x.OrderBy(o => o.DisplayName).ToList() }).ToList(); var favourites = new InstrumentTypeViewModel() { Type = AppProperties.FavouritesFolderName, Instruments = new List <InstrumentViewModel>() }; its.Insert(0, favourites); foreach (var fi in _settings.FavouriteInstruments) { var ivm = mapper.Map <InstrumentViewModel>(InstrumentCache.Lookup(fi)); if (ivm != null) { favourites.Instruments.Add(ivm); } } _allInstrumentTypes = new ObservableCollection <InstrumentTypeViewModel>(its); } catch (Exception) { MessageBox.Show("Failed to start application", AppProperties.ApplicationName); // throw; } } }