public ResponsePriceOil GetOilPriceTrend(RequestPriceOil r) { _logger.LogInformation("Ingresso : GetOilPriceTrend"); ResponsePriceOil ret = new ResponsePriceOil(); try { List <Prices> lstprice = new List <Prices>(); var _ReponcePrice = CallServicePriceOil(_conf.path_ooil); if (_ReponcePrice.StatusCode == System.Net.HttpStatusCode.OK) { // _logger.LogInformation($"r_ReponcePrice.Content : {_ReponcePrice.Content}"); lstprice = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Prices> >(_ReponcePrice.Content); var rangeprice = lstprice.Where(x => x.date >= r.Start_date && x.date <= r.End_date).ToList(); if (rangeprice.Count > 0) { ret = new ResponsePriceOil() { Prices = rangeprice }; } else { ret.Errors = new List <Error>() { new Error() { Code = "1002", Description = "Prices not available!" } }; } } else { _logger.LogInformation($"response._ReponcePrice.StatusCode : {_ReponcePrice.StatusCode} "); _logger.LogInformation($"response._ReponcePrice.ErrorMessage : {_ReponcePrice.ErrorMessage} "); } } catch (Exception ex) { ret.Errors = new List <Error>() { new Error() { Code = "'1", Description = ex.Message } }; _logger.LogError($"Errore GetOilPriceTrend: {ex}"); throw; } return(ret); }
public async Task <ResponsePriceOil> GetOilPriceTrend(string _start_date, string _end_date) { ResponsePriceOil ret = new ResponsePriceOil(); var _checkrequest = _service.Checkdate(_start_date.ToString(), _end_date.ToString()); if (_checkrequest.Errors.Count == 0) { var _r = new RequestPriceOil() { Start_date = Convert.ToDateTime(_start_date), End_date = Convert.ToDateTime(_end_date) }; try { ret = await Task.Run(() => _service.GetOilPriceTrend(_r)); } catch (Exception ex) { ret.Errors = new List <Error>() { new Error() { Code = "'1", Description = ex.Message } }; _logger.LogError($"Errore GetOilPriceTrend: {ex}"); throw; } } else { ret = _checkrequest; } return(ret); }