Ejemplo n.º 1
0
        public async Task <ActionResult <ExchangeRates> > GetExchangeRate(string baseCurrency, string convertedCurrency)
        {
            var currenciesController = new CurrenciesController();
            var baseCurrencyResult   = await currenciesController.GetCurrencies(baseCurrency.Replace("baseCurrency=", ""));

            var convertedCurrencyResult = await currenciesController.GetCurrencies(convertedCurrency.Replace("convertedCurrency=", ""));

            if (baseCurrencyResult.Value == null || convertedCurrencyResult.Value == null)
            {
                return(NotFound());
            }

            var query = await _context.ExchangeRates
                        .Where(s => s.BaseCurrecncy == baseCurrencyResult.Value.Id && s.ConvertedCurrency == convertedCurrencyResult.Value.Id)
                        .FirstOrDefaultAsync();

            if (query == null)
            {
                return(NotFound());
            }

            var log = new Logs
            {
                ExchangeId = query.Id,
                DateTime   = DateTime.Now
            };

            _context.Logs.Add(log);
            _context.SaveChanges();

            return(query);
        }
Ejemplo n.º 2
0
        //https://localhost:44318/api/Utility/DummyData
        public async Task <IActionResult> FillWithDummyData()
        {
            ClearDb();

            var currenciesController = new CurrenciesController();
            await currenciesController.AddCurrency(new Currencies
            {
                Exponent = 2,
                Symbol   = "£",
                Name     = "GBP"
            });

            await currenciesController.AddCurrency(new Currencies
            {
                Exponent = 2,
                Symbol   = "$",
                Name     = "USD"
            });

            await currenciesController.AddCurrency(new Currencies
            {
                Exponent = 2,
                Symbol   = "$",
                Name     = "AUD"
            });

            await currenciesController.AddCurrency(new Currencies
            {
                Exponent = 2,
                Symbol   = "€",
                Name     = "EUR"
            });

            ExchangeRatesController exchangeRateController = new ExchangeRatesController();
            await exchangeRateController.AddExchangeRate("GBP", "USD", 1);

            await exchangeRateController.AddExchangeRate("GBP", "AUD", (float)1.2);

            await exchangeRateController.AddExchangeRate("GBP", "EUR", (float)1.9);

            return(NoContent());
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <ExchangeRates> > AddExchangeRate(string baseCurrency, string convertedCurrency, float exchangeRate)
        {
            var currencyController = new CurrenciesController();
            var baseCurrencyId     = await currencyController.GetCurrencies(baseCurrency);

            var convertedCurrencyId = await currencyController.GetCurrencies(convertedCurrency);

            if (baseCurrencyId.Value == null || convertedCurrencyId.Value == null)
            {
                return(NotFound());
            }

            var exchangeRateObj = new ExchangeRates
            {
                BaseCurrecncy     = baseCurrencyId.Value.Id,
                ConvertedCurrency = convertedCurrencyId.Value.Id,
                ExchangeRate      = exchangeRate
            };

            _context.ExchangeRates.Add(exchangeRateObj);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetExchangeRates", exchangeRateObj));
        }