public CurrencyData GetBySymbol(string symbol) { if (!calculator.CurrencyExists(symbol)) { throw new HttpResponseException(HttpStatusCode.NotFound); } return(calculator.GetCurrencyData(symbol)); }
public MainWindow() { this.currencyCalculator = CurrencyCalculatorFactory.GetCalculator(); this.txtLeftValue = new TextBox() { Width = 80, Margin = new Thickness(10) }; this.txtRightValue = new TextBox() { Width = 80, Margin = new Thickness(10) }; this.cmbLeftCurrency = new ComboBox() { Margin = new Thickness(10) }; this.cmbRightCurrency = new ComboBox() { Margin = new Thickness(10) }; // Version 1: //foreach (var currency in currencyCalculator.GetCurrencyData()) //{ // this.cmbLeftCurrency.Items.Add(currency); // this.cmbRightCurrency.Items.Add(currency); //} // Version 2: var currencies = currencyCalculator.GetCurrencyData(); this.cmbLeftCurrency.ItemsSource = currencies; this.cmbRightCurrency.ItemsSource = currencies; StackPanel panel = new StackPanel(); panel.Children.Add(txtLeftValue); panel.Children.Add(cmbLeftCurrency); panel.Children.Add(txtRightValue); panel.Children.Add(cmbRightCurrency); panel.Orientation = Orientation.Horizontal; this.cmbLeftCurrency.SelectedItem = currencies.Where(p => p.Symbol == "CHF").First(); this.cmbRightCurrency.SelectedItem = currencies.Where(p => p.Symbol == "EUR").First(); this.cmbLeftCurrency.SelectionChanged += OnSelectionChanged; this.cmbRightCurrency.SelectionChanged += OnSelectionChanged; this.Content = panel; this.SizeToContent = SizeToContent.WidthAndHeight; }
public CurrencyCalculatorWindow() { txtLeftValue = new TextBox() { Width = 80 }; txtRightValue = new TextBox() { Width = 80 }; cmbLeftCurrency = new ComboBox() { Margin = new Thickness(5, 0, 5, 0) }; cmbRightCurrency = new ComboBox() { Margin = new Thickness(5, 0, 0, 0) }; StackPanel panel = new StackPanel() { Orientation = Orientation.Horizontal, Margin = new Thickness(10) }; panel.Children.Add(txtLeftValue); panel.Children.Add(cmbLeftCurrency); panel.Children.Add(txtRightValue); panel.Children.Add(cmbRightCurrency); this.Content = panel; this.Title = "WPF Currency Converter (Code)"; // wie sich der content des windows anpassen soll this.SizeToContent = SizeToContent.WidthAndHeight; this.ResizeMode = ResizeMode.NoResize; this.calculator = CurrencyCalculatorFactory.GetCalculator(); foreach (CurrencyData currency in calculator.GetCurrencyData()) { cmbLeftCurrency.Items.Add(currency); cmbRightCurrency.Items.Add(currency); } cmbLeftCurrency.SelectedIndex = cmbRightCurrency.SelectedIndex = 0; cmbLeftCurrency.SelectionChanged += OnSelectionChanged; cmbRightCurrency.SelectionChanged += OnSelectionChanged; txtLeftValue.TextChanged += OnTextChanged; txtRightValue.TextChanged += OnTextChanged; }
public CurrencyCalculatorWindow() { InitializeComponent(); calculator = CurrencyCalculatorFactory.GetCalculator(); IEnumerable <CurrencyData> currencies = calculator.GetCurrencyData(); cmbLeftCurrency.ItemsSource = cmbRightCurrency.ItemsSource = currencies; cmbLeftCurrency.SelectedItem = currencies.First(c => c.Symbol == "EUR"); cmbRightCurrency.SelectedItem = currencies.First(c => c.Symbol == "JPY"); }
public MainWindow() { InitializeComponent(); currencyCalcualtor = CurrencyCalculatorFactory.GetCalculator(); var currency = currencyCalcualtor.GetCurrencyData(); foreach (var currencyData in currency) { cmbLeftCurrency.Items.Add(currencyData); cmbRightCurrency.Items.Add(currencyData); } cmbLeftCurrency.SelectedItem = currency.First(c => c.Symbol == "EUR"); cmbRightCurrency.SelectedItem = currency.First(c => c.Symbol == "USD"); }