public Panel GetImdbInformationWithOptions(Int32 filmId, string title, Int32 userId, bool favourite, bool displayOverlay) { this.userId = userId; clsDataConnection DB = new clsDataConnection(); DB.AddParameter("@FilmId", filmId); DB.Execute("sproc_tblLinksFilterByFilmId"); string imdbId = DB.DataTable.Rows[0]["ImdbId"].ToString(); var client = new RestClient("https://movie-database-imdb-alternative.p.rapidapi.com/?i=" + imdbId); var request = new RestRequest(Method.GET); request.AddHeader("x-rapidapi-key", ConfigurationManager.AppSettings["RapidApiKey"]); request.AddHeader("x-rapidapi-host", "movie-database-imdb-alternative.p.rapidapi.com"); IRestResponse response = client.Execute(request); clsImdbAPI filmInfoReturned = new clsImdbAPI(); filmInfoReturned = Newtonsoft.Json.JsonConvert.DeserializeObject <clsImdbAPI>(response.Content); var imdbIdOk = filmInfoReturned.Response; Int32 count = 0; string numberOfZeroes = "0"; string newImdbId = "tt"; while (imdbIdOk == false) { newImdbId = "tt" + numberOfZeroes.PadRight(count, '0') + imdbId; newImdbId = newImdbId.Replace(" ", string.Empty); client = new RestClient("https://movie-database-imdb-alternative.p.rapidapi.com/?i=" + newImdbId); response = client.Execute(request); filmInfoReturned = new clsImdbAPI(); filmInfoReturned = Newtonsoft.Json.JsonConvert.DeserializeObject <clsImdbAPI>(response.Content); imdbIdOk = filmInfoReturned.Response; count++; } Panel pnlFilm = new Panel(); pnlFilm.CssClass = "filmWithTextContainer"; ImageButton imgbtnFilmPoster = new ImageButton(); imgbtnFilmPoster.CssClass = "image"; imgbtnFilmPoster.ImageUrl = filmInfoReturned.Poster; imgbtnFilmPoster.PostBackUrl = "FilmInformation.aspx?FilmId=" + filmId + "&ImdbId=" + newImdbId; pnlFilm.Controls.Add(imgbtnFilmPoster); if (displayOverlay) { Panel pnlOverlay = new Panel(); pnlOverlay.CssClass = "overlay"; ImageButton imgbtnRemove = new ImageButton(); imgbtnRemove.ImageUrl = "Images/Remove.png"; imgbtnRemove.CssClass = "overlay-itemRight"; if (favourite == true) { imgbtnRemove.CommandArgument = filmId.ToString(); imgbtnRemove.Command += RemoveFromFavourites; } else { imgbtnRemove.CommandArgument = filmId.ToString(); imgbtnRemove.Command += RemoveFromWatchList; } pnlOverlay.Controls.Add(imgbtnRemove); pnlFilm.Controls.Add(pnlOverlay); } Panel pnlFilmTitle = new Panel(); pnlFilmTitle.CssClass = "titleContainer"; Label lblFilmTitle = new Label(); lblFilmTitle.Text = title; lblFilmTitle.ToolTip = title; pnlFilmTitle.Controls.Add(lblFilmTitle); pnlFilm.Controls.Add(pnlFilmTitle); return(pnlFilm); }
public Panel GetImdbInformation(Int32 filmId) { clsLinkCollection AllLinks = new clsLinkCollection(); AllLinks.ThisLink.FilmId = filmId; AllLinks.GetLinkByFilmId(); string imdbId = AllLinks.ThisLink.ImdbId.ToString(); var client = new RestClient("https://movie-database-imdb-alternative.p.rapidapi.com/?i=" + imdbId); var request = new RestRequest(Method.GET); request.AddHeader("x-rapidapi-key", ConfigurationManager.AppSettings["RapidApiKey"]); request.AddHeader("x-rapidapi-host", "movie-database-imdb-alternative.p.rapidapi.com"); IRestResponse response = client.Execute(request); clsImdbAPI filmInfoReturned = new clsImdbAPI(); filmInfoReturned = Newtonsoft.Json.JsonConvert.DeserializeObject <clsImdbAPI>(response.Content); var imdbIdOk = filmInfoReturned.Response; Int32 count = 0; string numberOfZeroes = "0"; string newImdbId = "tt"; //this part is inefficient - needs looking at while (imdbIdOk == false) { newImdbId = newImdbId + numberOfZeroes.PadRight(count, '0') + imdbId; //may need the below if the search fails newImdbId = "tt" + numberOfZeroes.PadRight(count, '0') + imdbId; //newImdbId = newImdbId.Replace(" ", string.Empty); client = new RestClient("https://movie-database-imdb-alternative.p.rapidapi.com/?i=" + newImdbId); request = new RestRequest(Method.GET); request.AddHeader("x-rapidapi-key", ConfigurationManager.AppSettings["RapidApiKey"]); request.AddHeader("x-rapidapi-host", "movie-database-imdb-alternative.p.rapidapi.com"); response = client.Execute(request); filmInfoReturned = new clsImdbAPI(); filmInfoReturned = Newtonsoft.Json.JsonConvert.DeserializeObject <clsImdbAPI>(response.Content); imdbIdOk = filmInfoReturned.Response; count++; } Panel pnlFilm = new Panel(); pnlFilm.CssClass = "filmWithTextContainer"; ImageButton newClickableImage = new ImageButton(); newClickableImage.CssClass = "image"; newClickableImage.ImageUrl = filmInfoReturned.Poster; newClickableImage.PostBackUrl = "FilmInformation.aspx?FilmId=" + filmId + "&ImdbId=" + newImdbId; Panel pnlFilmTitle = new Panel(); pnlFilmTitle.CssClass = "titleContainer"; Label lblFilmTitle = new Label(); lblFilmTitle.Text = filmInfoReturned.Title; pnlFilmTitle.Controls.Add(lblFilmTitle); pnlFilm.Controls.Add(newClickableImage); pnlFilm.Controls.Add(pnlFilmTitle); return(pnlFilm); }
void DisplayFilm(string imdbId) { var client = new RestClient("https://movie-database-imdb-alternative.p.rapidapi.com/?i=" + imdbId); var request = new RestRequest(Method.GET); request.AddHeader("x-rapidapi-key", ConfigurationManager.AppSettings["RapidApiKey"]); request.AddHeader("x-rapidapi-host", "movie-database-imdb-alternative.p.rapidapi.com"); IRestResponse response = client.Execute(request); clsImdbAPI filmInfoReturned = new clsImdbAPI(); filmInfoReturned = new clsImdbAPI(); filmInfoReturned = Newtonsoft.Json.JsonConvert.DeserializeObject <clsImdbAPI>(response.Content); var imdbIdOk = filmInfoReturned.Response; Int32 count = 0; string numberOfZeroes = "0"; string newImdbId = "tt"; while (imdbIdOk == false) { newImdbId = "tt" + numberOfZeroes.PadRight(count, '0') + imdbId; newImdbId = newImdbId.Replace(" ", string.Empty); client = new RestClient("https://movie-database-imdb-alternative.p.rapidapi.com/?i=" + newImdbId); response = client.Execute(request); filmInfoReturned = new clsImdbAPI(); filmInfoReturned = Newtonsoft.Json.JsonConvert.DeserializeObject <clsImdbAPI>(response.Content); imdbIdOk = filmInfoReturned.Response; count++; } imgFilmPoster.ImageUrl = filmInfoReturned.Poster; lblTitle.Text = filmInfoReturned.Title + " (" + filmInfoReturned.Year + ")"; lblPlot.Text = filmInfoReturned.Plot; lblGenre.Text = filmInfoReturned.Genre; lblAgeRating.Text = filmInfoReturned.Rated; lblDirector.Text = filmInfoReturned.Director; lblRuntime.Text = filmInfoReturned.Runtime; lblReleased.Text = filmInfoReturned.Released; hyplnkMoreInformation.NavigateUrl = "https://www.imdb.com/title/" + filmInfoReturned.ImdbId + "/"; hyplnkMoreInformation.Text = "Click here"; if (displayOverlayContainer) { clsFavouriteFilm aFavouriteFilm = new clsFavouriteFilm(); if (aFavouriteFilm.Find(userId, filmId)) { filmInFavourites = true; Session["filmInFavourites"] = filmInFavourites; imgbtnFavourite.ImageUrl = "Images/FavouriteInList.png"; } clsWatchList aWatchListFilm = new clsWatchList(); if (aWatchListFilm.Find(userId, filmId)) { filmInWatchList = true; Session["filmInWatchList"] = filmInWatchList; imgbtnWatchLater.ImageUrl = "Images/WatchLaterAdded.png"; } clsFilmRatingCollection AllRatings = new clsFilmRatingCollection(); bool found = AllRatings.ThisFilmRating.Find(filmId, userId); if (found) { ddlRating.SelectedValue = Convert.ToString(AllRatings.ThisFilmRating.Rating); ratingExists = true; } else { ratingExists = false; } } else { pnlFilmOverlay.Visible = false; } pnlFilmInformation.Visible = true; }