public async Task <ServiceResult> Get()
        {
            var client   = clientFactory.CreateClient();
            var request  = new HttpRequestMessage(HttpMethod.Get, "https://itfllc.am/api/rate/exchange?from=12&to=1&value=1");
            var response = await client.SendAsync(request);

            CurrencyResponseModel responseModel = new CurrencyResponseModel();


            if (response.IsSuccessStatusCode)
            {
                var result = await response.Content.ReadAsStringAsync();

                var res = result.Split('"', ',', ':');

                return(new ServiceResult
                {
                    Data = new CurrencyResponseModel
                    {
                        Result = res[35],
                        Amount = res[39]
                    },
                    Success = true,
                });
            }
            ;

            return(new ServiceResult());
        }
        private IEnumerable <CurrencyResponseModel> CreateModel(
            DateTime startDate, DateTime endDate, IReadOnlyCollection <Currency> currencies)
        {
            var result = new List <CurrencyResponseModel>();

            while (startDate < endDate)
            {
                var date             = new DateTime(startDate.Year, startDate.Month, 1);
                var currenciesByDate = currencies.Where(e =>
                                                        date <= e.Date &&
                                                        e.Date <= date.AddDays(DateTime.DaysInMonth(date.Year, date.Month))
                                                        ).ToArray();

                var itemModel = new CurrencyResponseModel
                {
                    Year        = startDate.Year,
                    Month       = startDate.Month,
                    WeekPeriods = CreateWeekPeriods(startDate.Year, startDate.Month)
                };

                foreach (var currencyWeekPeriodModel in itemModel.WeekPeriods)
                {
                    var startWeekDate = new DateTime(
                        startDate.Year, startDate.Month, currencyWeekPeriodModel.StartDay);

                    var endWeekDate = new DateTime(
                        startDate.Year, startDate.Month, currencyWeekPeriodModel.EndDay);

                    var currenciesInPeriod = currenciesByDate
                                             .Where(e => startWeekDate <= e.Date && e.Date <= endWeekDate)
                                             .GroupBy(e => e.Code)
                                             .ToDictionary(e => e.Key, v => v.ToArray());

                    foreach (var code in _parameters.CurrenciesCodes)
                    {
                        var currenciesByCode = currenciesInPeriod.ContainsKey(code)
                            ? currenciesInPeriod[code]
                            : new Currency[0];

                        var collection = new CurrencyCollection();
                        collection.AddRange(currenciesByCode);

                        var model = new CurrencyResponseValueModel
                        {
                            Max    = collection.Max(),
                            Min    = collection.Min(),
                            Median = collection.Median(),
                            Code   = code
                        };
                        currencyWeekPeriodModel.Currencies.Add(model);
                    }
                }

                result.Add(itemModel);
                startDate = startDate.AddMonths(1);
            }

            return(result.OrderBy(e => e.Year).ThenBy(e => e.Month));
        }
        private CurrencyResponseModel ConvertToResponse(XDocument xmlDoc)
        {
            CurrencyResponseModel currencyModel = new CurrencyResponseModel();
            CultureInfo           culture       = new CultureInfo("en-US");

            currencyModel.Base  = xmlDoc.Element("channel").Element("baseCurrency").Value;
            currencyModel.Rates = xmlDoc.Descendants("channel").Elements("item").ToDictionary(
                x => x.Element("targetCurrency").Value,
                x => Math.Round(1 / Convert.ToDecimal(x.Element("exchangeRate").Value, culture), 4));
            return(currencyModel);
        }
        public IHttpActionResult GetCurrency(string baseValue = null, string date = null)
        {
            if (Debugger.IsAttached)
            {
                CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo("en-US");
            }
            CurrencyResponseModel currencyResponseModel = new CurrencyResponseModel();

            using (var currencyManager = new CurrencyManager())
            {
                currencyResponseModel = currencyManager.GetFloatRates(baseValue, date);
            }
            return(Json(currencyResponseModel));
        }