Пример #1
0
        public IActionResult UpdateExchangeRate(ExchangeRate request)
        {
            if (request.exchange_rate == 0 ||
                request.currency_input == 0 ||
                request.currency_output == 0)
            {
                return(BadRequest("No ha ingresado todos los campos obligatorios"));
            }
            ExchangeRate result = null, result2 = null;

            result = (from p in _context.ExchangeRates
                      where p.currency_input == request.currency_input && p.currency_output == request.currency_output
                      select p).SingleOrDefault();
            if (result == null)
            {
                result2 = (from p in _context.ExchangeRates
                           where p.currency_input == request.currency_output && p.currency_output == request.currency_input
                           select p).SingleOrDefault();
            }

            if (result != null)
            {
                result.exchange_rate = Math.Round(request.exchange_rate, 7);
            }


            if (result2 != null)
            {
                result2.exchange_rate = Math.Round(1 / request.exchange_rate, 7);
            }

            _context.SaveChanges();

            return(Ok(request));
        }
        public IActionResult UpdateExchangeRate(ExchangeRate request)
        {
            if (request.exchange_rate == 0 ||
                request.currency_input == null ||
                request.currency_input == String.Empty ||
                request.currency_output == null ||
                request.currency_output == String.Empty)
            {
                return(BadRequest("No ha ingresado todos los campos obligatorios"));
            }
            ExchangeRate result = (from p in _context.ExchangeRates
                                   where p.currency_input == request.currency_input && p.currency_output == request.currency_output
                                   select p).SingleOrDefault();

            result.exchange_rate = request.exchange_rate;

            _context.SaveChanges();

            return(Ok(request));
        }