/// <summary> /// Create a new instance of ThroughExchange /// </summary> /// <param name="initialCurrency">Initial currency to change</param> /// <param name="targetCurrency">Target currency to expected</param> /// <param name="throughExchange"></param> /// <param name="availableExchangeExcludeCurrent">All avalaible exchange currency to chain with current</param> /// <returns>Return new Direct Exchange</returns> public static IExchangeChain Create(IExchangeCurrency throughExchange, string initialCurrency, string targetCurrency, IList <IExchangeCurrency> availableExchangeExcludeCurrent) { string changeTo; if (!throughExchange.CanChangeFrom(initialCurrency, out changeTo)) { return(null); } var factory = new ExchangeChainFactory(availableExchangeExcludeCurrent); var nextExchange = factory.Create(changeTo, targetCurrency); if (nextExchange == null) { return(null); } return(new ThroughExchange { _initialCurrency = initialCurrency, _intermediateCurrency = changeTo, _throughExchange = throughExchange, _nextExchange = nextExchange }); }
/// <summary> /// Change money with current rate /// </summary> /// <param name="initialCurrency">Name of initial currency of a change</param> /// <param name="targetCurrency">Name target currency of a change</param> /// <param name="amount">Amount of money to change</param> /// <returns>Changed money</returns> public int Change(string initialCurrency, string targetCurrency, int amount) { if (AvailableExchangeCurrency.Count == 0) { throw new NotSupportedException(string.Format("Bank can not change from {0} to {1}. None exchange currency available.", initialCurrency, targetCurrency)); } var chainFactory = new ExchangeChainFactory(AvailableExchangeCurrency); var exchangeChain = chainFactory.Create(initialCurrency, targetCurrency); if (exchangeChain == null) { throw new NotSupportedException(string.Format("Bank can not change from {0} to {1}. None exchange currency corresponds to request change.", initialCurrency, targetCurrency)); } return(RoundChangeToInteger(exchangeChain.Change(amount))); }