public static decimal Get(Waehrung from, Waehrung to) { // exchange rate is 1:1 for same currency if (from == to) { return(1); } var key = string.Format("{0}{1}", from, to); // e.g. EURUSD means "How much is 1 EUR in USD?". // if we've already downloaded this exchange rate, use the cached value if (s_rates.ContainsKey(key)) { return(s_rates[key]); } // otherwise create the request URL, ... var url = string.Format(@"http://download.finance.yahoo.com/d/quotes.csv?s={0}=X&f=sl1d1t1c1ohgv&e=.csv", key); // download the response as string var data = new WebClient().DownloadString(url); // split the string at ',' var parts = data.Split(','); // convert the exchange rate part to a decimal var rate = decimal.Parse(parts[1], CultureInfo.InvariantCulture); s_rates[key] = rate; return(rate); }
public void UpdatePrice(decimal newPrice, Waehrung waehrung) { if (newPrice < 0) { throw new ArgumentException("Preis muss positiv sein.", nameof(newPrice)); } m_preis = new Preis(newPrice, waehrung); }
public Preis ConvertTo(Waehrung targetCurrency) { if (targetCurrency == Unit) { return(this); } return(new Preis(Amount * Umrechnung.Get(Unit, targetCurrency), targetCurrency)); }
public Geld(int betrag, Waehrung waehrung) { if (!IsValid(betrag, waehrung)) { throw new InvalidGeldValueException(betrag.ToString()); } this.Value = betrag; this.Waehrung = waehrung; }
public static decimal Get(Waehrung from, Waehrung to) { if (from == to) { return(1); } var key = string.Format("{0}{1}", from, to); if (s_rates.ContainsKey(key)) { return(s_rates[key]); } var url = string.Format(@"http://download.finance.yahoo.com/d/quotes.csv?s={0}=X&f=sl1d1t1c1ohgv&e=.csv", key); var data = new WebClient().DownloadString(url); var parts = data.Split(','); var rate = decimal.Parse(parts[1], CultureInfo.InvariantCulture); s_rates[key] = rate; return(rate); }
public Bremsen(string produzent, string modell, decimal price, Waehrung waehrung) : this(produzent, modell, new Preis(price, waehrung)) { }
public Reifen(string produzent, string modell, decimal preis, Waehrung waehrung) : this(produzent, modell, new Preis(preis, waehrung)) { }
public Schaltwerk(string produzent, string modell, decimal price, Waehrung waehrung) : this(produzent, modell, new Preis(price, waehrung)) { }
public Preis(decimal amount, Waehrung unit) { Amount = amount; Unit = unit; }
private bool IsValid(int betrag, Waehrung waehrung) => betrag >= 0 && waehrung != Waehrung.Undefined;