public static RatesDTO ToDTO(this Rates rate)
        {
            RatesDTO rateDto = new RatesDTO();

            rateDto.From = rate.From;
            rateDto.To   = rate.To;
            rateDto.Rate = rate.Rate;

            return(rateDto);
        }
Ejemplo n.º 2
0
        public static Rates RateDTO_To_Rate(RatesDTO entity)
        {
            Rates mappedEntity = new Rates
            {
                From = entity.From,
                To   = entity.To,
                Rate = entity.Rate
            };

            return(mappedEntity);
        }
Ejemplo n.º 3
0
        //Possible upgrade or improvement: Use Automapper or reflection with anonimous types and flags
        public static RatesDTO Rate_To_RateDTO(Rates entity)
        {
            RatesDTO mappedEntity = new RatesDTO
            {
                From = entity.From,
                To   = entity.To,
                Rate = entity.Rate
            };

            return(mappedEntity);
        }
Ejemplo n.º 4
0
        public List <RatesDTO> getRates()
        {
            string          sql  = "SELECT * FROM TIENTE";
            DataTable       data = ConnectionDB.getData(sql);
            List <RatesDTO> list = new List <RatesDTO>();

            for (int i = 0; i < data.Rows.Count; i++)
            {
                RatesDTO rates = new RatesDTO();
                rates.iMaTT   = data.Rows[i]["MaTT"].ToString();
                rates.iTenTT  = data.Rows[i]["TenTT"].ToString();
                rates.iTGQD   = data.Rows[i]["TGQD"].ToString();
                rates.iActive = bool.Parse(data.Rows[i]["Active"].ToString());
                list.Add(rates);
            }
            return(list);
        }
Ejemplo n.º 5
0
        private List <RatesDTO> GetToEuroRates(List <RatesDTO> lRates)
        {
            List <RatesDTO> conversedRates = new List <RatesDTO>();

            try
            {
                List <string> currencies = new List <string>();

                //Add to a list the different currencies
                currencies.AddRange(lRates.Select(x => x.From).Distinct());
                currencies.AddRange(lRates.Select(x => x.To).Distinct());
                currencies = currencies.Where(x => x != "EUR").Distinct().ToList();

                //Find direct conversions that we already have
                foreach (var currency in currencies)
                {
                    conversedRates.AddRange(lRates.Where(x => x.From == currency && x.To == "EUR"));
                }

                //Add to a new list the pending currencies which still doesn't have a conversion to EUR
                var pendingCurrencies = currencies.Except(conversedRates.Select(x => x.From)).ToList();

                //Simple (and dirty) control to avoid possible infinite loop if can't find conversions
                var maxRetry = 10;
                var counter  = 0;

                while (pendingCurrencies.Any() && counter < maxRetry)
                {
                    counter++;

                    foreach (var currency in pendingCurrencies)
                    {
                        //find a indirect conversion
                        var      currencyConversions = lRates.Where(x => x.From == currency).ToList();
                        var      indirectConversion  = new RatesDTO();
                        RatesDTO usedRate            = null;

                        foreach (var item in currencyConversions)
                        {
                            if ((indirectConversion = conversedRates.FirstOrDefault(x => x.From == item.To)) != null)
                            {
                                usedRate = item;
                                break;
                            }
                        }

                        //Use the indirect conversion to calculate the EUR conversion
                        if (usedRate != null)
                        {
                            conversedRates.Add(new RatesDTO
                            {
                                From = currency,
                                To   = "EUR",
                                Rate = RounderHelper.RoundToBankersRounding(usedRate.Rate * indirectConversion.Rate)
                            });

                            pendingCurrencies = pendingCurrencies.Except(conversedRates.Select(x => x.From)).ToList();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.LogError(ex.ToString());
            }

            return(conversedRates);
        }