Exemplo n.º 1
0
        //delete one or more instruments
        private async void DeleteInstrumentBtn_ItemClick(object sender, RoutedEventArgs routedEventArgs)
        {
            var selectedInstruments = InstrumentsGrid.SelectedItems;

            if (selectedInstruments.Count == 0)
            {
                return;
            }

            if (selectedInstruments.Count == 1)
            {
                var inst             = (Instrument)selectedInstruments[0];
                MessageBoxResult res = MessageBox.Show(string.Format("Are you sure you want to delete {0} @ {1}?", inst.Symbol, inst.Datasource.Name),
                                                       "Delete", MessageBoxButton.YesNo);
                if (res == MessageBoxResult.No)
                {
                    return;
                }
            }
            else
            {
                MessageBoxResult res = MessageBox.Show(string.Format("Are you sure you want to delete {0} instruments?", selectedInstruments.Count),
                                                       "Delete", MessageBoxButton.YesNo);
                if (res == MessageBoxResult.No)
                {
                    return;
                }
            }

            List <Instrument> toRemove = new List <Instrument>();

            foreach (Instrument i in InstrumentsGrid.SelectedItems)
            {
                await _client.DeleteInstrument(i).ConfigureAwait(true);

                toRemove.Add(i);
            }

            while (toRemove.Count > 0)
            {
                Instruments.Remove(toRemove[toRemove.Count - 1]);
                toRemove.RemoveAt(toRemove.Count - 1);
            }
        }