public RatesEO Get(string fromCurrency, string toCurrency) { RatesEO Rates = null; List <RatesEO> listRates; try { if (!string.IsNullOrEmpty(fromCurrency) && !string.IsNullOrEmpty(toCurrency)) { listRates = _dataAccess.ListConversion(); if (listRates != null) { Rates = Utilities.Instance.CalculateConversion(listRates, fromCurrency, toCurrency); if (Rates == null) { throw new Exception("Conversion no disponible"); } } else { throw new Exception("El acceso a la informacion no se encuentra disponible en estos momentos. Por favor intentelo mas tarde."); } } else { throw new Exception("Parametros obligatorios para la conversión de moneda"); } return(Rates); } catch (Exception ex) { _fileLog.WriteLog(string.Format("{0}. Origen de la excepcion:{1}.", ex.Message, ex.StackTrace)); return(Rates); } }
public TransactionsEO GetBySku(string sku) { TransactionsEO transaction = null; List <TransactionsEO> listTransactions = null; string currency = System.Configuration.ConfigurationManager.AppSettings["Currency"].ToUpper(); try { listTransactions = _dataAccess.ListTransaction(); if (listTransactions != null) { if (listTransactions.Any(t => t.Sku.ToUpper() == sku.ToUpper())) { decimal totalAmount = 0; RatesEO objRate = null; List <RatesEO> listRate = _conversionCurrency.List(); if (listRate == null) { throw new Exception("Informacion de conversion de moneda no disponible intente mas tarde."); } foreach (TransactionsEO itemTransaction in listTransactions.Where(t => t.Sku.ToUpper() == sku.ToUpper())) { if (itemTransaction.Currency.ToUpper() != currency) { objRate = Utilities.Instance.CalculateConversion(listRate, itemTransaction.Currency, currency); if (objRate != null) { totalAmount = totalAmount + (objRate.rate * itemTransaction.Amount); } else { throw new Exception("Conversion no disponible"); } } else { totalAmount = totalAmount + itemTransaction.Amount; } } transaction = new TransactionsEO() { Sku = sku.ToUpper(), Currency = currency, Amount = Math.Ceiling(totalAmount) }; return(transaction); } else { throw new Exception(string.Format("No existen productos asociados al proucto {0}", sku)); } } else { throw new Exception("El acceso a la informacion no se encuentra disponible en estos momentos. Por favor intentelo mas tarde."); } } catch (Exception ex) { _fileLog.WriteLog(string.Format("{0}. Origen de la excepcion:{1}.", ex.Message, ex.StackTrace)); return(transaction); } }