public async Task <sunlightDataModel> GetData(int?itemNumber) { string url; if (itemNumber.HasValue && itemNumber > 0) { url = $"http://xkcd.com/{itemNumber}/info.0.json"; } else { url = $"http://xkcd.com/info.0.json"; } using (HttpResponseMessage response = await ApiHelper.ApiHelper.apiClient.GetAsync(url)) { if (response.IsSuccessStatusCode) { sunlightDataModel model = await response.Content.ReadAsAsync <sunlightDataModel>(); return(model); } else { throw new Exception(response.ReasonPhrase); } } }
public async Task <IActionResult> Index(int?seek) { sunlightDataModel model = new sunlightDataModel(); model = await _sunLightService.GetData(seek); return(View(model)); }