public async Task <IActionResult> GetVersesData(VersesData versesData) { VerseResponses verses = new VerseResponses(); try { if (!ModelState.IsValid) { return(View()); } VersesRepository versesRepository = new VersesRepository(_dbContext); verses = await versesRepository.GetVerses(versesData); for (int x = 0; x < verses.Verses.Count; x++) { verses.Verses[x].TwitterShareUrl = System.Web.HttpUtility.UrlEncode(verses.Verses[x].TwitterShareUrl); verses.Verses[x].PinterestShareUrl = System.Web.HttpUtility.UrlEncode(verses.Verses[x].PinterestShareUrl); verses.Verses[x].Url = System.Web.HttpUtility.UrlEncode(verses.Verses[x].Url); } } catch { return(View("Error")); } return(View(verses)); }
public async Task <VerseResponses> GetVerses(VersesData versesData) { VerseResponses versesList = new VerseResponses(); try { using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Clear(); httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "d10161af8cf44f0c8267d571c682fda4"); using (var KLoveResponse = await httpClient.GetAsync("https://emfservicesstage-api.azure-api.net/bible/v1/getversesbydate?siteId=1&startdate=" + versesData.VerseDate.ToString("MM/dd/yyyy") + "&PageSize=" + versesData.NumberOfVerses.ToString())) { string KLoveApiResponse = await KLoveResponse.Content.ReadAsStringAsync(); versesList = JsonConvert.DeserializeObject <VerseResponses>(KLoveApiResponse); } } } catch (Exception ex) { // please - more error handling System.Diagnostics.Debug.Print(ex.Message); } return(versesList); }