public static void Initialize(CurrencyContext context) { context.Database.EnsureCreated(); //creates tables if (!context.USD_AUD.Any()) { context.USD_AUD.AddRange( USD_AUD_Data.Get() .Select(l => new USD_AUD { Date = l.Date, Value = l.Value }) .ToList()); } if (!context.USD_EUR.Any()) { context.USD_EUR.AddRange( USD_EUR_Data.Get() .Select(l => new USD_EUR { Date = l.Date, Value = l.Value }) .ToList()); } if (!context.EUR_AUD.Any()) { context.EUR_AUD.AddRange( EUR_AUD_Data.Get() .Select(l => new EUR_AUD { Date = l.Date, Value = l.Value }) .ToList()); } context.SaveChanges(); }
public CurrencyRates GetExchangeRates(Currency baseCurrency, Currency rateCurrency, DateTime start, DateTime end) { var exchangeRates = new CurrencyRates { DataSource = DataSource.Fallback, BaseCurrency = baseCurrency.ToString(), RateCurrency = rateCurrency.ToString() }; if (baseCurrency == Currency.USD && rateCurrency == Currency.AUD) { exchangeRates.Rates = USD_AUD_Data .Get() .Where(c => c.Date >= start && c.Date <= end) .ToList(); } if (baseCurrency == Currency.AUD && rateCurrency == Currency.USD) { exchangeRates.Rates = USD_AUD_Data .Get() .Where(c => c.Date >= start && c.Date <= end) .ToList(); exchangeRates.Rates.ForEach(r => r.Value = 1.0 / r.Value); } if (baseCurrency == Currency.USD && rateCurrency == Currency.EUR) { exchangeRates.Rates = USD_EUR_Data .Get() .Where(c => c.Date >= start && c.Date <= end) .ToList(); } if (baseCurrency == Currency.EUR && rateCurrency == Currency.USD) { exchangeRates.Rates = USD_EUR_Data .Get() .Where(c => c.Date >= start && c.Date <= end) .ToList(); exchangeRates.Rates.ForEach(r => r.Value = 1.0 / r.Value); } if (baseCurrency == Currency.EUR && rateCurrency == Currency.AUD) { exchangeRates.Rates = EUR_AUD_Data .Get() .Where(c => c.Date >= start && c.Date <= end) .ToList(); } if (baseCurrency == Currency.AUD && rateCurrency == Currency.EUR) { exchangeRates.Rates = EUR_AUD_Data .Get() .Where(c => c.Date >= start && c.Date <= end) .ToList(); exchangeRates.Rates.ForEach(r => r.Value = 1.0 / r.Value); } return exchangeRates; }