/// <summary>
            /// Get list of currency codes supported by current channel.
            /// </summary>
            /// <param name="context">Request context.</param>
            /// <returns>Collection of currency codes.</returns>
            private static IEnumerable <string> GetCurrencyCodeSupportedByChannel(RequestContext context)
            {
                GetChannelCurrenciesDataRequest dataRequest = new GetChannelCurrenciesDataRequest(QueryResultSettings.AllRecords);
                IEnumerable <CurrencyAmount>    currencies  = context.Execute <EntityDataServiceResponse <CurrencyAmount> >(dataRequest).PagedEntityCollection.Results;

                return(currencies.Select(c => c.CurrencyCode));
            }
Пример #2
0
            private EntityDataServiceResponse <CurrencyAmount> GetChannelCurrencies(GetChannelCurrenciesDataRequest request)
            {
                CurrencyDataManager manager = this.GetDataManagerInstance(request.RequestContext);

                PagedResult <CurrencyAmount> currencies = manager.GetChannelCurrencies(request.QueryResultSettings);

                return(new EntityDataServiceResponse <CurrencyAmount>(currencies));
            }
Пример #3
0
            /// <summary>
            /// Gets all supported channel currency value and exchange rate for the given amount.
            /// </summary>
            /// <param name="request">Request contains the amount to be converted.</param>
            /// <returns>The converted amount with exchange rates.</returns>
            private static GetChannelCurrencyServiceResponse GetSupportedChannelCurrencies(GetChannelCurrencyServiceRequest request)
            {
                string fromCurrencyCode = request.CurrencyCode;

                GetChannelCurrenciesDataRequest     dataRequest            = new GetChannelCurrenciesDataRequest(request.QueryResultSettings ?? QueryResultSettings.AllRecords);
                PagedResult <CurrencyAmount>        pagedChannelCurrencies = request.RequestContext.Execute <EntityDataServiceResponse <CurrencyAmount> >(dataRequest).PagedEntityCollection;
                ReadOnlyCollection <CurrencyAmount> channelCurrencies      = pagedChannelCurrencies.Results;

                if (channelCurrencies == null || !channelCurrencies.Any())
                {
                    NetTracer.Warning("Cannot find channel currencies");
                    return(new GetChannelCurrencyServiceResponse());
                }

                var currencyList = channelCurrencies.ToList();

                foreach (var toCurrency in currencyList)
                {
                    var getCurrencyValueRequest = new GetCurrencyValueServiceRequest(fromCurrencyCode, toCurrency.CurrencyCode, request.Amount);
                    GetCurrencyValueServiceResponse serviceResponse = GetCurrencyConversion(request.RequestContext, getCurrencyValueRequest);
                    toCurrency.ExchangeRate           = serviceResponse.ExchangeRate;
                    toCurrency.ConvertedAmount        = serviceResponse.ConvertedAmount;
                    toCurrency.RoundedConvertedAmount = serviceResponse.RoundedConvertedAmount;
                }

                var storeCurrencyList = currencyList.Where(currency => currency.ExchangeRate > 0M).ToList();

                // If the from currency does not exists add to the list.
                if (storeCurrencyList.All(currency => string.CompareOrdinal(currency.CurrencyCode, fromCurrencyCode) != 0))
                {
                    CurrencyAmount conversionResult = GetFromCurrencyAmount(request.RequestContext, request.Amount, fromCurrencyCode);
                    storeCurrencyList.Add(conversionResult);
                }

                pagedChannelCurrencies.Results = storeCurrencyList.AsReadOnly();

                return(new GetChannelCurrencyServiceResponse(pagedChannelCurrencies));
            }