Exemple #1
0
        public List <ImdbEntity> Recherche()
        {
            List <ImdbEntity> listInit = new List <ImdbEntity>();
            ImdbEntity        obj      = new ImdbEntity();
            List <string>     URL      = new List <string>() // Liste de film sur la page de départ par défaut
            {
                "http://www.omdbapi.com/?apikey=" + OMDBKey + "&t=captain&page=1",
                "http://www.omdbapi.com/?apikey=" + OMDBKey + "&t=Marvel&page=1",
                "http://www.omdbapi.com/?apikey=" + OMDBKey + "&t=iron&page=1",
                "http://www.omdbapi.com/?apikey=" + OMDBKey + "&t=Sword%20Art%20Online&page=1",
                "http://www.omdbapi.com/?apikey=" + OMDBKey + "&t=The%20Fugitive&page=1",
                "http://www.omdbapi.com/?apikey=" + OMDBKey + "&t=Fast%20&%20Furious%206&page=1",
                "http://www.omdbapi.com/?apikey=" + OMDBKey + "&t=Blindspot&page=1",
                "http://www.omdbapi.com/?apikey=" + OMDBKey + "&t=Home%20Alone&page=1",
                "http://www.omdbapi.com/?apikey=" + OMDBKey + "&t=Bourne&page=1",
                "http://www.omdbapi.com/?apikey=" + OMDBKey + "&t=avengers&page=1"
            };

            foreach (var url in URL)
            {
                using (WebClient wc = new WebClient())
                {
                    var json = wc.DownloadString(url);
                    obj = Newtonsoft.Json.JsonConvert.DeserializeObject <ImdbEntity>(json);
                    listInit.Add(obj);
                }
            }
            return(listInit);
        }
        // GET: Movies/Details/5
        public async Task <IActionResult> Details(string id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var movie = await _context.Movie
                        .FirstOrDefaultAsync(m => m.MovieID == id);

            if (movie == null)
            {
                return(NotFound());
            }
            ImdbEntity imdbMovie = OmdbFetcher(movie.Title);

            if (imdbMovie == null || imdbMovie.Poster == "N/A")
            {
                ViewData["Poster"] = "/assets/img/MovieMonsterLogo.jpg";
            }
            else
            {
                ViewData["Poster"] = imdbMovie.Poster;
            }
            ViewData["Title"] = new SelectList(_context.Movie, "Title", "Title");
            return(View(movie));
        }
Exemple #3
0
        private async Task Run(ImdbEntity imdb) //API de youtube en async
        {
            var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey          = "AIzaSyDbb9kUcOZUNxY-h5mgZjnOinkNbH5YYxo",
                ApplicationName = this.GetType().ToString()
            });
            var searchListRequest = youtubeService.Search.List("snippet");

            searchListRequest.Q          = imdb.Title + " Official trailer"; // Recherche par titre pour bande annonce
            searchListRequest.MaxResults = 1;                                //S'assure d'avoir le résultat le plus pertinent
            var searchListResponse = await searchListRequest.ExecuteAsync();

            List <string> videos = new List <string>();

            // Récupère les vidéos correspondantes
            foreach (var searchResult in searchListResponse.Items)
            {
                switch (searchResult.Id.Kind)
                {
                case "youtube#video":
                    videos.Add(String.Format(searchResult.Id.VideoId));
                    break;
                }
            }
            ViewData["URLYoutube"] = "https://www.youtube.com/watch?v=" + videos.FirstOrDefault(); //Renvoie l'url de la vidéo
        }
Exemple #4
0
        protected void displayMovie()
        {
            try {
                Movie selectedMovie = db.movies.SqlQuery("SELECT * FROM Movie WHERE movieID=" + currentEvent.movieID).FirstOrDefault();
                var   html          = "";
                phNextMovies.Controls.Clear();
                string url = "http://www.omdbapi.com/?&apikey=b9bb3ece&i=" + selectedMovie.omdbCode;
                using (WebClient wc = new WebClient())
                {
                    var json = wc.DownloadString(url);
                    JavaScriptSerializer oJS        = new JavaScriptSerializer();
                    ImdbEntity           imdbEntity = new ImdbEntity();
                    imdbEntity = oJS.Deserialize <ImdbEntity>(json);
                    if (imdbEntity.Response == "True")
                    {
                        html = "";


                        html += "<div \" id=\"" + imdbEntity.imdbID + "\">";
                        html += "\t\t<h4>" + imdbEntity.Title + "</h4>";
                        html += "\t<div class=\"hovereffect\" style=\"height: 496px; width: 360px;\">\n";

                        if (imdbEntity.Poster == "N/A")
                        {
                            html += "\t\t\t<img height=\"496px\" width=\"360px\" class=\"img - responsive\"  src='images/defaultPoster.jpg'>\n";
                        }
                        else
                        {
                            html += "\t\t<img height=\"496px\" width= \"360px\"  class=\"img - responsive\" src='" + imdbEntity.Poster + "'>\n";
                        }

                        html += "<div class=\"overlay\">";
                        html += "<h2 class=\"\" style=\" padding: 1rem;\">Released: " + imdbEntity.Year + "</h2>";
                        html += "<p class=\"text-muted\" style=\"text-align: left; padding: 1rem;\">" + imdbEntity.Plot + "</p>";
                        html += "<ul>";
                        html += "<li><p style=\"float: left; padding-left: 1rem;\">Runtime: " + imdbEntity.Runtime + "</p><p style=\"float: right; padding-right: 1rem;\">Rated:" + imdbEntity.Rated + "</li>";
                        html += "</ul>";


                        html += "\t\t<a class=\"info link1 text-small\" href=\"https://www.imdb.com/title/" + imdbEntity.imdbID + "\" style=\"margin-right: 1rem\">Link to IMDB</a>";
                        phNextMovies.Controls.Add(new Literal {
                            Text = html
                        });

                        html  = "";
                        html += "</div>";
                        html += "</div>";
                        html += "</div>";

                        phNextMovies.Controls.Add(new Literal {
                            Text = html
                        });
                    }
                }
            } catch (Exception)
            {
                lblError.Text = "Unable to display movie";
            }
        }
        protected void displayMoviesList(User picker)
        {
            movieDropdown.Items.Clear();
            movieDropdown.Items.Add("Select a Movie");

            try
            {
                //List of current movies to be picked
                nextMoviesAvalible = db.movies.SqlQuery("SELECT Movie.movieID, Movie.omdbCode FROM Movie INNER JOIN UserMovie on Movie.movieID = UserMovie.movieID WHERE userID = " + picker.userID + "ORDER BY dateAdded Desc").ToList <Movie>();

                phNextMovies.Controls.Clear();
                String html = "";
                phNextMovies.Controls.Add(new Literal {
                    Text = html
                });

                if (nextMoviesAvalible.Count() == 0)
                {
                    movieDropdown.Items.Add("No Movies to Display.");

                    html  = "";
                    html += "<p>Add movies to your list <a href=\"movieSearch.aspx\" style=\"color: blue;\">here</a>.</p>";
                    html += "\t\t\t<img height=\"480px\" width=\"360px\" class=\"img - responsive\"  src='images/defaultPoster.jpg'>\n";
                    phNextMovies.Controls.Add(new Literal {
                        Text = html
                    });
                }
                else
                {
                    foreach (Movie movie in nextMoviesAvalible)
                    {
                        string url = "http://www.omdbapi.com/?&apikey=b9bb3ece&i=" + movie.omdbCode;
                        using (WebClient wc = new WebClient())
                        {
                            var json = wc.DownloadString(url);
                            JavaScriptSerializer oJS        = new JavaScriptSerializer();
                            ImdbEntity           imdbEntity = new ImdbEntity();
                            imdbEntity = oJS.Deserialize <ImdbEntity>(json);
                            if (imdbEntity.Response == "True")
                            {
                                ListItem item = new ListItem(imdbEntity.Title.ToString(), imdbEntity.imdbID.ToString());

                                movieDropdown.Items.Add(item);
                            }
                            else
                            {
                                html += "<li>\n";
                                html += "\t<p>Movie not added</p>\n";
                                html += "</li>\n";
                            }
                        }
                    }
                }
            } catch (Exception)
            {
                lblMovie.InnerText = "Movie - Cannot get movies";
            }
        }
        /*-----------------My Function----------------*/
        //fetch data from IMDB
        // disconnect from gave the jeson and convert him to object
        public ImdbEntity OmdbFetcher(string title)
        {
            ImdbEntity obj  = new ImdbEntity();
            var        json = DownloadJesonMovie(title);

            obj = JsonConvert.DeserializeObject <ImdbEntity>(DownloadJesonMovie(title));
            if (obj.Response.Equals("True"))
            {
                return(obj);
            }
            else
            {
                return(null);
            }
        }
Exemple #7
0
        public static string callImdb(string txtMovieName)
        {
            {
                string apikey = ConfigurationManager.AppSettings["apikey"];
                string apiurl = ConfigurationManager.AppSettings["apiurl"];
                string url    = apiurl + txtMovieName.Trim() + "&" + apikey;

                using (WebClient wc = new WebClient())
                {
                    try
                    {
                        string html = wc.DownloadString(url);
                        var    json = wc.DownloadString(url);
                        JavaScriptSerializer oJS = new JavaScriptSerializer();
                        ImdbEntity           obj = new ImdbEntity();
                        obj = oJS.Deserialize <ImdbEntity>(json);
                        if (obj.Response == "True")
                        {
                            string data = obj.Genre.ToString();
                            string date = obj.Released.ToString();

                            DateTime releaseDate      = Convert.ToDateTime(date);
                            TimeSpan ts               = DateTime.Now - releaseDate;
                            int      differenceInDays = ts.Days;
                            if (differenceInDays < 180)
                            {
                                return("New Releases");
                            }
                            else
                            {
                                string value = data.Split(',')[0];
                                return(value);
                            }
                        }
                        else
                        {
                            return("unknown");
                        }
                    }

                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message.ToString() + ", " + ex.InnerException.ToString());
                        return("Error, chek log");
                    }
                }
            }
        }
Exemple #8
0
        public IActionResult Details(string imdbID)
        {
            ImdbEntity imdb = new ImdbEntity();
            string     url  = "http://www.omdbapi.com/?apikey=" + OMDBKey + "&i=" + imdbID;

            using (WebClient wc = new WebClient())
            {
                var json = wc.DownloadString(url);
                imdb = Newtonsoft.Json.JsonConvert.DeserializeObject <ImdbEntity>(json);
            }
            try
            {
                Run(imdb).Wait();
            }
            catch (AggregateException ex)
            {
                foreach (var e in ex.InnerExceptions)
                {
                    Console.WriteLine("Error: " + e.Message);
                }
            }
            return(View(imdb));
        }
Exemple #9
0
    public static string GetPosterURL(string Title)
    {
        // This Method retrieves the URL for each film when the object is created.
        // This string stores the PosterURL when it is retrieved.
        string PosterURL = "";
        // This string contains the beginning of the API call and then the name of the Film is added to the end to complete it.
        string url = "http://www.omdbapi.com/?t=" + Title.Trim();

        using (WebClient wc = new WebClient())
        {
            var json = wc.DownloadString(url);
            // This Initializes a new instance of the JavaScriptSerializer class that has no type resolver.
            JavaScriptSerializer oJS = new JavaScriptSerializer();
            // This Initializes a new instance of the ImdbEntity class.
            ImdbEntity obj = new ImdbEntity();
            obj = oJS.Deserialize <ImdbEntity>(json);
            if (obj.Response != null)
            {
                PosterURL = obj.Poster;
            }
        }
        return(PosterURL);
    }
        public async Task <IActionResult> Create([Bind("MovieID,Title,Genere,UnitsInStock,YearRelease,Actors,Rated,Language,Wholesale,Retail")] Movie movie)
        {
            // need change YearReleased and Reated
            if (ModelState.IsValid)
            {
                ImdbEntity imdbMovie = OmdbFetcher(movie.Title);
                if (imdbMovie != null)
                {
                    movie.Genere = imdbMovie.Genre;
                    if (!imdbMovie.Year.Equals("N/A"))
                    {
                        movie.YearRelease = int.Parse(imdbMovie.Year);
                    }
                    movie.Actors   = imdbMovie.Actors;
                    movie.Rated    = imdbMovie.Rated;
                    movie.Language = imdbMovie.Language;
                }
                _context.Add(movie);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(movie));
        }
Exemple #11
0
        private Boolean ProcessRequest(string searchRequestString)
        {
            List <string> requestSplit = searchRequestString.Split(new char[] { AgentConstants.INTERNET_SEARCH_REQUEST_SEPARATOR_CHARACTER },
                                                                   StringSplitOptions.RemoveEmptyEntries).ToList();

            if (requestSplit[0].ToUpper() == "RSS")
            {
                if (requestSplit.Count == 5)
                {
                    RSSAction rssAction;
                    try
                    {
                        rssAction = (RSSAction)Enum.Parse(typeof(RSSAction), requestSplit[1]);
                    }
                    catch
                    {
                        return(false);
                    }
                    string        topicString = requestSplit[2];
                    List <string> topicList   = topicString.Split(new char[] { AgentConstants.INTERNET_SEARCH_REQUEST_LIST_LEFT_CHARACTER,
                                                                               AgentConstants.INTERNET_SEARCH_REQUEST_LIST_RIGHT_CHARACTER, AgentConstants.INTERNET_SEARCH_REQUEST_LIST_SEPARATOR_CHARACTER },
                                                                  StringSplitOptions.RemoveEmptyEntries).
                                                ToList();
                    string  url = requestSplit[3];
                    string  customDateTimeFormatString = requestSplit[4];
                    Boolean rssOK = ProcessRSSRequest(url, topicList, customDateTimeFormatString, rssAction);
                    return(rssOK);
                }
                else
                {
                    return(false);
                }
            }
            else if (requestSplit[0].ToUpper().TrimEnd(new char[] { ' ' }) == "WIKI")
            {
                if (requestSplit.Count == 3)
                {
                    string        category           = requestSplit[1].Replace(" ", "");
                    string        rawRequestString   = requestSplit[2].TrimStart(new char[] { ' ' }).TrimEnd(new char[] { });
                    List <string> requestStringSplit = rawRequestString.Split(new char[] { ' ' },
                                                                              StringSplitOptions.RemoveEmptyEntries).ToList();
                    string requestString = "";
                    foreach (string requestItem in requestStringSplit)
                    {
                        requestString += requestItem[0].ToString().ToUpper() + requestItem.Remove(0, 1) + "_";
                    }
                    requestString = requestString.TrimEnd(new char[] { '_' });
                    Boolean wikiOK = ProcessWikipediaRequest(category, requestString);
                    if (!wikiOK)
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else if (requestSplit[0].ToUpper().TrimEnd(new char[] { ' ' }) == "IMDB")
            {
                string txtMovieName = requestSplit[1].Replace(" ", "");
                string url          = "http://www.omdbapi.com/?t=" + txtMovieName.Trim() + "&apikey=c983ca13";
                // http://www.omdbapi.com/?t=scream&apikey=c983ca13 url for the movie scream
                using (WebClient wc = new WebClient())
                {
                    var json = wc.DownloadString(url);
                    JavaScriptSerializer oJS = new JavaScriptSerializer();
                    ImdbEntity           obj = new ImdbEntity();
                    obj = oJS.Deserialize <ImdbEntity>(json);
                    if (obj.Response == "True")
                    {
                        string movieTitle = obj.Title;
                        double imdbRating = Convert.ToDouble(obj.imdbRating);
                        int    year       = Convert.ToInt16(obj.Year);
                        string genre      = obj.Genre;
                        //var _ultraManager = UltraManager.Instance;

                        Movie newMovie = new Movie(movieTitle, year, imdbRating, genre);
                        //_ultraManager.MovieList.Add(newMovie);
                        // Send only the first sentence:
                        string message = "[" + AgentConstants.LONG_TERM_MEMORY_NAME + "]";
                        message += "[{";
                        message += "testCategory";
                        message += "}]";
                        string movieInformationString = newMovie.Title + " is a " + newMovie.Genre + " from " + newMovie.Year + " that has a imdb rating of " + newMovie.ImdbRating;
                        message += "[name = testName" + AgentConstants.MEMORY_ITEM_SEPARATION_CHARACTER + "description = " + movieInformationString + "]";
                        client.Send(message);
                        ThreadSafeShowSearchResult(message);
                    }
                    else
                    {
                        string message = "[" + AgentConstants.LONG_TERM_MEMORY_NAME + "]";
                        message += "[{";
                        message += "testCategory";
                        message += "}]";
                        string movieInformationString = "the movie could not be found";
                        message += "[name = testName" + AgentConstants.MEMORY_ITEM_SEPARATION_CHARACTER + "description = " + movieInformationString + "]";
                        client.Send(message);
                        ThreadSafeShowSearchResult(message);
                        //Debug.WriteLine("not found");
                        //string message = "neinneinneienineinneinneinnein";
                        //client.Send(message);
                        //ThreadSafeShowSearchResult(message);
                        return(false);
                    }
                }
                string message2 = "[" + AgentConstants.LONG_TERM_MEMORY_NAME + "]";
                message2 += "[{";
                message2 += "testCategory";
                message2 += "}]";
                string movieInformationString2 = "the movie could not be found";
                message2 += "[name = testName" + AgentConstants.MEMORY_ITEM_SEPARATION_CHARACTER + "description = " + movieInformationString2 + "]";
                client.Send(message2);
                ThreadSafeShowSearchResult(message2);
            }
            else // To be written: Processing other requests than RSS requests and Wikipedia searches
            {
                string message2 = "[" + AgentConstants.LONG_TERM_MEMORY_NAME + "]";
                message2 += "[{";
                message2 += "testCategory";
                message2 += "}]";
                string movieInformationString2 = "the movie could not be found";
                message2 += "[name = testName" + AgentConstants.MEMORY_ITEM_SEPARATION_CHARACTER + "description = " + movieInformationString2 + "]";
                client.Send(message2);
                ThreadSafeShowSearchResult(message2);
                return(false);
            }
            return(true);
        }
Exemple #12
0
        protected void displayMoviesList(User picker)
        {
            try
            {
                //List of current movies to be picked
                List <Movie> moviesAvalible = db.movies.SqlQuery("SELECT Movie.movieID, Movie.omdbCode FROM Movie INNER JOIN UserMovie on Movie.movieID = UserMovie.movieID WHERE userID = " + picker.userID).ToList <Movie>();
                if (moviesAvalible != null)
                {
                    String html = "";

                    phMovies.Controls.Clear();
                    html += "<div class=\"row\">\n";
                    phMovies.Controls.Add(new Literal {
                        Text = html
                    });

                    foreach (Movie movie in moviesAvalible)
                    {
                        string url = "http://www.omdbapi.com/?&apikey=b9bb3ece&i=" + movie.omdbCode;
                        using (WebClient wc = new WebClient())
                        {
                            var json = wc.DownloadString(url);
                            JavaScriptSerializer oJS        = new JavaScriptSerializer();
                            ImdbEntity           imdbEntity = new ImdbEntity();
                            imdbEntity = oJS.Deserialize <ImdbEntity>(json);
                            if (imdbEntity.Response == "True")
                            {
                                html  = "";
                                html += "<div class=\"col-lg-4\" style=\" margin-top: 1rem; height: 450px; width: 314px\">\n";
                                html += "\t<div class=\"hovereffect\" style=\"height: 450px; width: 314px\">\n";
                                if (imdbEntity.Poster == "N/A")
                                {
                                    html += "\t\t\t<img height=\"450px\" width=\"314px\" class=\"img - responsive\"  src='images/defaultPoster.jpg'>\n";
                                }
                                else
                                {
                                    html += "\t\t<img height=\"450px\" width= \"314px\"  class=\"img - responsive\" src='" + imdbEntity.Poster + "'>\n";
                                }
                                html += "<div class=\"overlay\">";
                                html += "\t\t<h2>" + imdbEntity.Title + " (" + imdbEntity.Year + ")</h2>";
                                html += "<p class=\"text-muted\" style=\"text-align: left; padding: 1rem;\">" + imdbEntity.Plot + "</p>";
                                html += "<ul>";
                                html += "<li><p style=\"float: left; padding-left: 1rem;\">Runtime: " + imdbEntity.Runtime + "</p><p style=\"float: right; padding-right: 1rem;\">Rated:" + imdbEntity.Rated + "</li>";
                                html += "</ul>";

                                html += "\t\t<a class=\"info link1 text-small\" href=\"https://www.imdb.com/title/" + imdbEntity.imdbID + "\" style=\"margin-right: 1rem\">Link to IMDB</a>";
                                phMovies.Controls.Add(new Literal {
                                    Text = html
                                });

                                LinkButton btnAddMovie = new LinkButton();
                                btnAddMovie.ID              = "addMovie" + imdbEntity.imdbID;
                                btnAddMovie.Click          += new EventHandler(btnRemove_Click);
                                btnAddMovie.CssClass        = "info link2 text-small";
                                btnAddMovie.Text            = "Remove Movie";
                                btnAddMovie.CommandName     = "removeMovie";
                                btnAddMovie.CommandArgument = imdbEntity.imdbID;
                                phMovies.Controls.Add(btnAddMovie);

                                html  = "";
                                html += "\t</div>";
                                html += "</div>\n";
                                html += "</div>";
                                phMovies.Controls.Add(new Literal {
                                    Text = html
                                });
                            }
                            else
                            {
                                html += "<li>\n";
                                html += "\t<p>No movies added</p>\n";
                                html += "</li>\n";
                            }
                        }
                    }

                    html  = "";
                    html += "</div>\n";
                    phMovies.Controls.Add(new Literal {
                        Text = html
                    });
                }
                else
                {
                    lblError.Text = "You have not added any movies.";
                }
            } catch (Exception)
            {
                lblError.Text = "Unable to get your movies.";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            welcomeText.InnerText = "Welcome " + currentUser.userName.TrimEnd(' ', '\t') + ", please create a new event.";


            DateTime currentDate = DateTime.Now;



            lblTickets.ForeColor = System.Drawing.Color.Gray;
            txtTickets.Enabled   = false;
            rvTickets.Enabled    = false;


            if (IsPostBack) //Post back rollover of date/time
            {
                try
                {
                    selectedMovieIndex = movieDropdown.SelectedIndex;
                    var html = "";
                    phNextMovies.Controls.Clear();
                    string url = "http://www.omdbapi.com/?&apikey=b9bb3ece&i=" + movieDropdown.SelectedValue;
                    using (WebClient wc = new WebClient())
                    {
                        var json = wc.DownloadString(url);
                        JavaScriptSerializer oJS        = new JavaScriptSerializer();
                        ImdbEntity           imdbEntity = new ImdbEntity();
                        imdbEntity = oJS.Deserialize <ImdbEntity>(json);
                        if (imdbEntity.Response == "True")
                        {
                            html = "";


                            html += "<div \" id=\"" + imdbEntity.imdbID + "\">";

                            html += "\t<div class=\"hovereffect\" style=\"height: 496px; width: 360px;\">\n";

                            if (imdbEntity.Poster == "N/A")
                            {
                                html += "\t\t\t<img height=\"496px\" width=\"360px\" class=\"img - responsive\"  src='images/defaultPoster.jpg'>\n";
                            }
                            else
                            {
                                html += "\t\t<img height=\"496px\" width= \"360px\"  class=\"img - responsive\" src='" + imdbEntity.Poster + "'>\n";
                            }

                            html += "<div class=\"overlay\">";
                            html += "\t\t<h2>" + imdbEntity.Title + " (" + imdbEntity.Year + ")</h2>";
                            html += "<p class=\"text-muted\" style=\"text-align: left; padding: 1rem;\">" + imdbEntity.Plot + "</p>";
                            html += "<ul>";
                            html += "<li><p style=\"float: left; padding-left: 1rem;\">Runtime: " + imdbEntity.Runtime + "</p><p style=\"float: right; padding-right: 1rem;\">Rated:" + imdbEntity.Rated + "</li>";
                            html += "</ul>";

                            html += "\t\t<a class=\"info link1 text-small\" href=\"https://www.imdb.com/title/" + imdbEntity.imdbID + "\" style=\"margin-right: 1rem\">Link to IMDB</a>";
                            phNextMovies.Controls.Add(new Literal {
                                Text = html
                            });

                            //Button btnAddMovie = new Button();
                            //btnAddMovie.ID = "addMovie" + imdbEntity.imdbID;
                            //btnAddMovie.Click += new EventHandler(btnRemove_Click);
                            //btnAddMovie.CssClass = "btn btn-primary";
                            //btnAddMovie.Text = "Remove Movie";
                            //btnAddMovie.CommandName = "removeMovie";
                            //btnAddMovie.CommandArgument = imdbEntity.imdbID;
                            //phNextMovies.Controls.Add(btnAddMovie);


                            html  = "";
                            html += "</div>";
                            html += "</div>";
                            html += "</div>";
                            phNextMovies.Controls.Add(new Literal {
                                Text = html
                            });
                        }
                    }
                }
                catch (Exception)
                {
                    lblMovie.InnerText = "Movie - Unable to get movie";
                }


                if (Request[txtDate.UniqueID] != null)
                {
                    if (Request[txtDate.UniqueID].Length > 0)
                    {
                        txtDate.Text = Request[txtDate.UniqueID];
                    }
                }

                if (Request[txtTime.UniqueID] != null)
                {
                    if (Request[txtTime.UniqueID].Length > 0)
                    {
                        txtTime.Text = Request[txtTime.UniqueID];
                    }
                }
            }
            else //Not Post Back
            {
                txtDate.Text = currentDate.ToString("yyyy-MM-dd");
                txtTime.Text = currentDate.AddHours(1).Hour.ToString() + ":00";
            }
        }
        protected void movieDropdown_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                selectedMovieIndex = movieDropdown.SelectedIndex;
                var html = "";
                phNextMovies.Controls.Clear();
                string url = "http://www.omdbapi.com/?&apikey=b9bb3ece&i=" + movieDropdown.SelectedValue;
                using (WebClient wc = new WebClient())
                {
                    var json = wc.DownloadString(url);
                    JavaScriptSerializer oJS        = new JavaScriptSerializer();
                    ImdbEntity           imdbEntity = new ImdbEntity();
                    imdbEntity = oJS.Deserialize <ImdbEntity>(json);
                    if (imdbEntity.Response == "True")
                    {
                        html = "";


                        html += "<div \" id=\"" + imdbEntity.imdbID + "\">";

                        html += "\t<div class=\"hovereffect\" style=\"height: 496px; width: 360px;\">\n";

                        if (imdbEntity.Poster == "N/A")
                        {
                            html += "\t\t\t<img height=\"496px\" width=\"360px\" class=\"img - responsive\"  src='images/defaultPoster.jpg'>\n";
                        }
                        else
                        {
                            html += "\t\t<img height=\"496px\" width= \"360px\"  class=\"img - responsive\" src='" + imdbEntity.Poster + "'>\n";
                        }

                        html += "<div class=\"overlay\">";
                        html += "\t\t<h2>" + imdbEntity.Title + " (" + imdbEntity.Year + ")</h2>";
                        html += "<p class=\"text-muted\" style=\"text-align: left; padding: 1rem;\">" + imdbEntity.Plot + "</p>";
                        html += "<ul>";
                        html += "<li><p style=\"float: left; padding-left: 1rem;\">Runtime: " + imdbEntity.Runtime + "</p><p style=\"float: right; padding-right: 1rem;\">Rated:" + imdbEntity.Rated + "</li>";
                        html += "</ul>";

                        html += "\t\t<a class=\"info link1 text-small\" href=\"https://www.imdb.com/title/" + imdbEntity.imdbID + "\" style=\"margin-right: 1rem\">Link to IMDB</a>";
                        phNextMovies.Controls.Add(new Literal {
                            Text = html
                        });

                        //Button btnAddMovie = new Button();
                        //btnAddMovie.ID = "addMovie" + imdbEntity.imdbID;
                        //btnAddMovie.Click += new EventHandler(btnRemove_Click);
                        //btnAddMovie.CssClass = "btn btn-primary";
                        //btnAddMovie.Text = "Remove Movie";
                        //btnAddMovie.CommandName = "removeMovie";
                        //btnAddMovie.CommandArgument = imdbEntity.imdbID;
                        //phNextMovies.Controls.Add(btnAddMovie);


                        html  = "";
                        html += "</div>";
                        html += "</div>";
                        html += "</div>";
                        phNextMovies.Controls.Add(new Literal {
                            Text = html
                        });
                    }
                }
            } catch (Exception)
            {
                lblMovie.InnerText = "Movie - Unable to get movie";
            }
        }
Exemple #15
0
        protected void displayMoviesList(User picker)
        {
            //List of current movies to be picked
            try
            {
                usersMovies = db.movies.SqlQuery("SELECT Movie.movieID, Movie.omdbCode FROM Movie INNER JOIN UserMovie on Movie.movieID = UserMovie.movieID WHERE userID = " + picker.userID + "ORDER BY dateAdded Desc ").ToList <Movie>();
                phUserMovies.Controls.Clear();
                phUserMovieTab.Controls.Clear();
                String html = "";
                phUserMovies.Controls.Add(new Literal {
                    Text = html
                });
                int count  = 0;
                var active = "";
                var show   = "";
                var space  = "";
                if (usersMovies.Count() == 0)
                {
                    html += "<h4>No Movies to Display.</h4>";
                    html += "<p>Add movies to your list <a href=\"movieSearch.aspx\" style=\"color: blue;\">here</a>.</p>";
                    phUserMovieTab.Controls.Add(new Literal {
                        Text = html
                    });

                    html  = "";
                    html += "\t\t\t<img height=\"480px\" width=\"360px\" class=\"img - responsive\"  src='images/defaultPoster.jpg'>\n";
                    phUserMovies.Controls.Add(new Literal {
                        Text = html
                    });
                }
                else
                {
                    foreach (Movie movie in usersMovies)
                    {
                        count += 1;

                        if (count == 1)
                        {
                            active = "active";
                            show   = "show";
                            space  = " ";
                        }
                        else
                        {
                            active = "";
                            show   = "";
                            space  = "";
                        }

                        string url = "http://www.omdbapi.com/?&apikey=b9bb3ece&i=" + movie.omdbCode;
                        using (WebClient wc = new WebClient())
                        {
                            var json = wc.DownloadString(url);
                            JavaScriptSerializer oJS        = new JavaScriptSerializer();
                            ImdbEntity           imdbEntity = new ImdbEntity();
                            imdbEntity = oJS.Deserialize <ImdbEntity>(json);
                            if (imdbEntity.Response == "True" && count <= 4)
                            {
                                html = "";

                                html += "<li class=\"nav-item\">";
                                html += "<a class=\"nav-link" + space + active + "\" style=\"padding-left: 17.6px; padding-right: 17.6px;\" data-toggle=\"tab\" href=\"#" + movie.omdbCode + "\">Movie " + count + "</a>";
                                html += "</li>";
                                phUserMovieTab.Controls.Add(new Literal {
                                    Text = html
                                });


                                html = "";

                                html += "<div class=\"tab-pane fade" + space + active + space + show + space + "\" id=\"" + movie.omdbCode + "\">";

                                html += "\t<div class=\"hovereffect\" style=\"height: 496px; width: 360px;\">\n";
                                if (imdbEntity.Poster == "N/A")
                                {
                                    html += "\t\t\t<img height=\"496px\" width=\"360px\" class=\"img - responsive\"  src='images/defaultPoster.jpg'>\n";
                                }
                                else
                                {
                                    html += "\t\t<img height=\"496px\" width= \"360px\"  class=\"img - responsive\" src='" + imdbEntity.Poster + "'>\n";
                                }
                                html += "<div class=\"overlay\">";
                                html += "\t\t<h2>" + imdbEntity.Title + " (" + imdbEntity.Year + ")</h2>";
                                html += "<p class=\"text-muted\" style=\"text-align: left; padding: 1rem;\">" + imdbEntity.Plot + "</p>";
                                html += "<ul>";
                                html += "<li><p style=\"float: left; padding-left: 1rem;\">Runtime: " + imdbEntity.Runtime + "</p><p style=\"float: right; padding-right: 1rem;\">Rated:" + imdbEntity.Rated + "</li>";
                                html += "</ul>";

                                html += "\t\t<a class=\"info link1 text-small\" href=\"https://www.imdb.com/title/" + imdbEntity.imdbID + "\" style=\"margin-right: 1rem\">Link to IMDB</a>";
                                phUserMovies.Controls.Add(new Literal {
                                    Text = html
                                });

                                LinkButton btnAddMovie = new LinkButton();
                                btnAddMovie.ID              = "addMovie" + imdbEntity.imdbID;
                                btnAddMovie.Click          += new EventHandler(btnRemove_Click);
                                btnAddMovie.CssClass        = "info link2 text-small";
                                btnAddMovie.Text            = "Remove Movie";
                                btnAddMovie.CommandName     = "removeMovie";
                                btnAddMovie.CommandArgument = imdbEntity.imdbID;

                                phUserMovies.Controls.Add(btnAddMovie);

                                html  = "";
                                html += "\t</div>";
                                html += "</div>\n";
                                html += "</div>";
                                phUserMovies.Controls.Add(new Literal {
                                    Text = html
                                });
                            }
                            else
                            {
                            }
                        }
                    }
                }
            } catch (Exception)
            {
                //Movies will not display
                phUserMovies.Controls.Add(new Literal {
                    Text = "Unable to display movies"
                });
            }
        }
        // Buttons need to be created in the Page_Init function if you want their click event handlers to have any effect.  Thus, we redirect the user to the same page(with an extra url parameter) with the search click handler. We then check for the parameter to see if we need to call the api and create the new html to display movies.
        protected void Page_Init(object sender, EventArgs e)
        {
            if (Session["userAccount"] != null)
            {
                currentUser = (User)Session["userAccount"];
            }
            else
            {
                Session["redirectTo"] = "movieSearch.aspx";
                Response.Redirect("CreateAccount.aspx");
            }


            if (Request.QueryString["title"] != null)
            {
                try
                {
                    using (WebClient wc = new WebClient())
                    {
                        String url  = "http://www.omdbapi.com/?&apikey=b9bb3ece&s=" + Request.QueryString["title"];
                        var    json = wc.DownloadString(url);
                        JavaScriptSerializer oJS             = new JavaScriptSerializer();
                        ImdbEntityArray      imdbEntityArray = new ImdbEntityArray();
                        imdbEntityArray = oJS.Deserialize <ImdbEntityArray>(json);
                        if (imdbEntityArray.Search != null)
                        {
                            String html = "";
                            phMovieResults.Controls.Clear();
                            html += "<div class=\"row\">\n";
                            phMovieResults.Controls.Add(new Literal {
                                Text = html
                            });

                            foreach (ImdbEntity movie in imdbEntityArray.Search)
                            {
                                String url2  = "http://www.omdbapi.com/?&apikey=b9bb3ece&i=" + movie.imdbID;
                                var    json2 = wc.DownloadString(url2);
                                JavaScriptSerializer oJS2       = new JavaScriptSerializer();
                                ImdbEntity           imdbEntity = new ImdbEntity();
                                imdbEntity = oJS2.Deserialize <ImdbEntity>(json2);

                                html  = "";
                                html += "<div class=\"col-lg-4\" style=\"padding: 7px, 7px, 7px, 7px; margin-top: 1rem; height: 450px; width: 314px\">\n";
                                html += "\t<div class=\"hovereffect\" style=\"height: 450px; width: 314px\">\n";

                                if (movie.Poster == "N/A")
                                {
                                    html += "\t\t<h6>" + movie.Title + " (" + movie.Year + ")</h6>";
                                    html += "\t\t\t<img height=\"450px\" width=\"314px\" class=\"img - responsive\"  src='images/defaultPoster.jpg'>\n";
                                }
                                else
                                {
                                    html += "\t\t<img height=\"450px\" width= \"314px\"  class=\"img - responsive\" src='" + movie.Poster + "'>\n";
                                }

                                html += "<div class=\"overlay\">";
                                html += "\t\t<h2>" + movie.Title + " (" + movie.Year + ")</h2>";
                                html += "<p class=\"text-muted\" style=\"text-align: left; padding: 1rem;\">" + imdbEntity.Plot + "</p>";
                                html += "<ul>";
                                html += "<li><p style=\"float: left; padding-left: 1rem;\">Runtime: " + imdbEntity.Runtime + "</p><p style=\"float: right; padding-right: 1rem;\">Rated:" + imdbEntity.Rated + "</li>";
                                html += "</ul>";

                                html += "\t\t<a class=\"info link1\" href=\"https://www.imdb.com/title/" + movie.imdbID + "\" style=\"margin-right: 1rem\">Link to IMDB</a>";
                                phMovieResults.Controls.Add(new Literal {
                                    Text = html
                                });

                                LinkButton btnAddMovie = new LinkButton();
                                btnAddMovie.Click          += new EventHandler(btnAddMovie_Click);
                                btnAddMovie.CssClass        = "info link2";
                                btnAddMovie.Text            = "Add Movie";
                                btnAddMovie.CommandName     = "addMovie";
                                btnAddMovie.CommandArgument = movie.imdbID;

                                phMovieResults.Controls.Add(btnAddMovie);

                                html  = "";
                                html += "\t</div>";
                                html += "</div>\n";
                                html += "</div>";
                                phMovieResults.Controls.Add(new Literal {
                                    Text = html
                                });
                            }


                            html  = "";
                            html += "</div>\n";
                            phMovieResults.Controls.Add(new Literal {
                                Text = html
                            });
                        }
                        else
                        {
                            String html = "";
                            html += "<li>\n";
                            html += "\t<p>Movie not Found!!!</p>\n";
                            html += "</li>\n";
                            phMovieResults.Controls.Add(new Literal {
                                Text = html
                            });
                        }
                    }
                } catch (Exception)
                {
                    lblResult.Text = "Unable to fetch movies";
                }
            }
        }