Esempio n. 1
0
        public async Task <ViliborDto> GetViliborRate(BaseRateCode baseRateCode)
        {
            var url      = $"http://www.lb.lt/webservices/VilibidVilibor/VilibidVilibor.asmx/getLatestVilibRate?RateType={baseRateCode}";
            var request  = new HttpRequestMessage(HttpMethod.Get, url);
            var client   = _httpClientFactory.CreateClient();
            var response = await client.SendAsync(request);

            if (!response.IsSuccessStatusCode)
            {
                return(new ViliborDto
                {
                    IsSuccess = false,
                    BaseRateValue = null,
                });
            }

            var responseString = await response.Content.ReadAsStringAsync();

            var baseRateString = XDocument.Parse(responseString).Descendants().First(x => x.Name.LocalName == "decimal").Value;
            var baseRateValue  = decimal.Parse(baseRateString.Replace(".", ","));

            return(new ViliborDto
            {
                IsSuccess = true,
                BaseRateValue = baseRateValue,
            });
        }
Esempio n. 2
0
        private async Task <ViliborDto> GetBaseRate(BaseRateCode baseRateCode)
        {
            var     isSuccess     = true;
            var     cacheDto      = _cache.GetBaseRateValue(baseRateCode);
            decimal?baseRateValue = cacheDto.Property;

            if (!cacheDto.IsSuccess)
            {
                var viliborDto = await _viliborClient.GetViliborRate(baseRateCode);

                if (!viliborDto.IsSuccess)
                {
                    isSuccess = false;
                }

                baseRateValue = viliborDto.BaseRateValue;

                _cache.SetBaseRateValue(baseRateCode, baseRateValue ?? 0);
            }

            return(new ViliborDto
            {
                IsSuccess = isSuccess,
                BaseRateValue = baseRateValue,
            });
        }
        public IActionResult Index()
        {
            BaseRateCode code = BaseRateCode.VILIBOR1m;

            var rate = _baseRateReposirory.GetRate(code).Result;

            return(View(rate));
        }
        private async Task <(decimal, decimal)> GetBaseRateValuesAsync(BaseRateCode currentBaseRateCode, BaseRateCode newBaseRateCode)
        {
            var newBaseRateValue = await _baseRateService.GetBaseRateValue(newBaseRateCode.ToString());

            var currentBaseRateValue = currentBaseRateCode == newBaseRateCode
                ? newBaseRateValue
                : await _baseRateService.GetBaseRateValue(currentBaseRateCode.ToString());

            return(currentBaseRateValue, newBaseRateValue);
        }
Esempio n. 5
0
        public CacheDto <decimal?> GetBaseRateValue(BaseRateCode baseRateCode)
        {
            var  cacheKey  = GetBaseRateCacheKey(baseRateCode);
            bool isSuccess = _cache.TryGetValue(cacheKey, out decimal value);

            return(new CacheDto <decimal?>
            {
                IsSuccess = isSuccess,
                Property = value
            });
        }
        public async Task <decimal> GetRate(BaseRateCode baseRateCode)
        {
            using (var client = new HttpClient())
            {
                var uri = new Uri($"http://old.lb.lt/webservices/VilibidVilibor/VilibidVilibor.asmx/getLatestVilibRate?RateType={baseRateCode}");

                var response = await client.GetAsync(uri);

                string textResult = await response.Content.ReadAsStringAsync();

                var result = textResult.Replace("</decimal>", "");
                int index  = result.LastIndexOf('>');
                return(decimal.Parse(result.Remove(0, index + 1)));
            }
        }
Esempio n. 7
0
 private string GetBaseRateCacheKey(BaseRateCode baseRateCode)
 {
     return(_baseRateValueCacheKeyPrefix + baseRateCode.ToString());
 }
Esempio n. 8
0
        public void SetBaseRateValue(BaseRateCode baseRateCode, decimal baseRateValue)
        {
            var cacheKey = GetBaseRateCacheKey(baseRateCode);

            _cache.Set(cacheKey, baseRateValue, _baseRateCacheOptions);
        }