public ActionResult Index(Models.TheMovieDb theMovieDb, string searchText) { var searchActorsResponse = new SearchActorsResponse(); if (ModelState.IsValid) { searchActorsResponse = GetActors(searchText, 0); } return(View(searchActorsResponse)); }
public SearchActorsResponse GetActors(string searchText, int page) { int pageNo = Convert.ToInt32(page) == 0 ? 1 : Convert.ToInt32(page); /*Calling API https://developers.themoviedb.org/3/search/search-people */ string apiKey = ConfigurationManager.AppSettings["ApiKey"]; HttpWebRequest apiRequest = WebRequest.Create("https://api.themoviedb.org/3/search/person?api_key=" + apiKey + "&language=en-US&query=" + searchText + "&page=" + pageNo + "&include_adult=false") as HttpWebRequest; string apiResponse = ""; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; using (HttpWebResponse response = apiRequest.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(response.GetResponseStream()); apiResponse = reader.ReadToEnd(); } /*End*/ /*http://json2csharp.com*/ SearchActorsResponse rootObject = JsonConvert.DeserializeObject <SearchActorsResponse>(apiResponse); int pageSize = 20; PagingInfo pagingInfo = new PagingInfo(); pagingInfo.currentPage = pageNo; pagingInfo.totalItems = rootObject.total_results; pagingInfo.itemsPerPage = pageSize; ViewBag.Paging = pagingInfo; return(rootObject); }