public IEnumerable <Stat> FindBetween(DateTime from, DateTime to) { try { var statbydate = new StatByDate() { From = from, To = to }; var content = new StringContent(JsonConvert.SerializeObject(statbydate), Encoding.UTF8, "application/json"); var response = _httpClient.PostAsync("/api/admin/stats/bydate", content).Result; if (!response.IsSuccessStatusCode) { logger.LogError("Error while retrieve stats from HTTPRepo repository "); throw new Exception("Error while retrieve stats from HTTPRepo repository"); } var stats = JsonConvert.DeserializeObject <IEnumerable <Stat> >(response.Content.ReadAsStringAsync().Result); return(stats); } catch (Exception ex) { logger.LogError("Error while retrieve stats from HTTPRepo repository " + ex); throw new Exception(ex.Message); } }
public IActionResult Post([FromBody] StatByDate statbydate) { try { var stats = _statsService.GetBetween(statbydate.From, statbydate.To); return(Ok(stats)); } catch (Exception ex) { var exc = ex.InnerException ?? ex; return(StatusCode((int)HttpStatusCode.InternalServerError, exc)); } }