Exemplo n.º 1
0
        public CurrencyRate Add(CurrencyRateDTO currencyRateDTO)
        {
            CurrencyRate currencyRate = _mapper.Map <CurrencyRate>(currencyRateDTO);

            _currencyRatesRepo.Add(currencyRate);
            return(currencyRate);
        }
Exemplo n.º 2
0
        public CurrencyRateDTO Update([FromBody] CurrencyRateDTO currencyRateDTO)
        {
            var updatedCurrencyRate = _srv.Update(currencyRateDTO);

            _unitOfWork.Commit();

            return(_srv.MapToDTO(updatedCurrencyRate));
        }
Exemplo n.º 3
0
 public CurrencyRate(CurrencyRateDTO currencyRateDto)
 {
     Id               = Guid.NewGuid().ToString();
     CurrencyId       = currencyRateDto.Id;
     Name             = currencyRateDto.Nombre;
     PercentageChange = currencyRateDto.VariacionPorcentual;
     Buy              = currencyRateDto.Compra;
     Sell             = currencyRateDto.Venta;
     LastUpdated      = currencyRateDto.UltimaActualizacion;
     Sort             = currencyRateDto.Orden;
 }
        public static CurrencyRateDTO MapToDTO(this CurrencyRate currencyRate)
        {
            CurrencyRateDTO currencyDTO = new CurrencyRateDTO()
            {
                Code           = currencyRate.Currency.Code,
                CurrencyRateId = currencyRate.Id,
                Date           = currencyRate.DateRefreshed.ToAppString(),
                ExchangeRate   = currencyRate.ExchangeRate,
                Name           = currencyRate.Currency.Name
            };

            return(currencyDTO);
        }
Exemplo n.º 5
0
        public ActionResult <CurrencyRateDTO> Add([FromBody] CurrencyRateDTO currencyRateDTO)
        {
            if (_srv.GetByCurrencyIds(currencyRateDTO.BaseCurrencyId, currencyRateDTO.TargetCurrencyId) != null)
            {
                throw new ApplicationException("Currency Pair rate already exists");
            }

            var addedCurrencyRate = _srv.Add(currencyRateDTO);

            _unitOfWork.Commit();

            return(CreatedAtAction(nameof(GetById), new { id = addedCurrencyRate.Id }, _srv.MapToDTO(addedCurrencyRate)));
        }
Exemplo n.º 6
0
        public CurrencyRate Update(CurrencyRateDTO currencyRateDTO)
        {
            CurrencyRate currencyRate = _mapper.Map <CurrencyRate>(currencyRateDTO);

            _currencyRatesRepo.Update(currencyRate);

            //Update the reverse currency pair rate depending on the setting
            if (_updateReverseRate)
            {
                CurrencyRate oppositeCurrencyRate = _currencyRatesRepo.GetByIds(currencyRate.TargetCurrencyId, currencyRate.BaseCurrencyId);
                if (oppositeCurrencyRate != null && currencyRate.Rate != 0)
                {
                    oppositeCurrencyRate.Rate = 1 / currencyRate.Rate;
                }
            }
            return(currencyRate);
        }