private async Task UpdateOMDBDataSource() { try { int page = short.Parse(labelPage.Text); OMDBMoviesResult result = await _OMDBService.GetMoviesList(page, textBoxSearch.Text); // update form values with result textBoxRequestValue.Text = "Request was successfull"; labelResultsValue.Text = result.totalResults ?? "0"; // configure columns DataTable dt = new DataTable(); dt.Columns.Add("Title"); dt.Columns.Add("Year"); dt.Columns.Add("Type"); if (result.Search != null) { foreach (var item in result.Search) { dt.Rows.Add(item.Title, item.Year, item.Type); } } gridOMDB.DataSource = dt; } catch (Exception e) { textBoxRequestValue.Text = e.Message; } }
public async Task <OMDBMoviesResult> GetMoviesList(int page, string name) { // build request params from configs string request = $"{ConfigurationManager.AppSettings["OMDBAPI.Address"]}/?apikey={ConfigurationManager.AppSettings["OMDBAPI.Key"]}&s={name}&page={page}"; HttpResponseMessage result = await _client.GetAsync(request); if (result.IsSuccessStatusCode) { string resultContent = await result.Content.ReadAsStringAsync(); OMDBMoviesResult OMDBMoviesResult = JsonConvert.DeserializeObject <OMDBMoviesResult>(resultContent); return(OMDBMoviesResult); } else { throw new Exception("Request wasn't successfull"); } }