private void AddBtn_Click(object sender, RoutedEventArgs e) { int count = 0; using (var context = new MyDBContext()) { var instrumentSource = new InstrumentRepository(context); foreach (Instrument newInstrument in InstrumentGrid.SelectedItems) { if (newInstrument.Exchange != null) { newInstrument.ExchangeID = newInstrument.Exchange.ID; } if (newInstrument.PrimaryExchange != null) { newInstrument.PrimaryExchangeID = newInstrument.PrimaryExchange.ID; } try { if (instrumentSource.AddInstrument(newInstrument) != null) { count++; } AddedInstruments.Add(newInstrument); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } } } StatusLabel.Content = string.Format("{0}/{1} instruments added.", count, InstrumentGrid.SelectedItems.Count); }
private void AddBtn_Click(object sender, RoutedEventArgs e) { int count = 0; using (var context = new MyDBContext()) { var instrumentSource = new InstrumentRepository(context); foreach (FredUtils.FredSeries series in InstrumentGrid.SelectedItems) { var newInstrument = FredUtils.SeriesToInstrument(series); newInstrument.Datasource = _thisDS; try { if (instrumentSource.AddInstrument(newInstrument) != null) { count++; } AddedInstruments.Add(newInstrument); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } } } StatusLabel.Content = string.Format("{0}/{1} instruments added.", count, InstrumentGrid.SelectedItems.Count); }
private bool TryAddInstrument(InstrumentRepository instrumentSource, Instrument newInstrument, bool showDialogs = true) { try { if (instrumentSource.AddInstrument(newInstrument) != null) { AddedInstruments.Add(newInstrument); return(true); } } catch (Exception ex) { if (showDialogs) { _dialogService.ShowMessageAsync(this, "Error", ex.Message); } _logger.Log(NLog.LogLevel.Warn, ex, "Error adding instrument"); } return(false); }
private bool TryAddInstrument(InstrumentRepository instrumentSource, Instrument newInstrument, bool showDialogs = true) { try { if (instrumentSource.AddInstrument(newInstrument).Result.ID != 0) { //if (AddedInstruments.Contains(newInstrument)) return false; AddedInstruments.Add(newInstrument); return(true); } } catch (Exception ex) { if (showDialogs) { dialogService.ShowMessageAsync(this, "Error", ex.Message); } Logger.Log(LogLevel.Warn, ex, "Error adding instrument"); } return(false); }