Ejemplo n.º 1
0
        public MovieClass GetMovie(int id)
        {
            MovieClass movie = null;

            using (var connection = new SqlConnection(DatabaseClass.ConnectionString))
                using (var command = new SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandText = "Select * from Movie WHERE MovieID = @Id";

                    command.Parameters.AddWithValue("@Id", id);

                    connection.Open();

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            movie = new MovieClass((int)reader[0], (string)reader[1], (string)reader[2], (string)reader[3],
                                                   (string)reader[4], (DateTime)reader[5], (Decimal)reader[6], (string)reader[7], (string)reader[8], (int)reader[9]);
                        }
                    }
                }
            return(movie);
        }
        public static void insertMovie(SqlCommand command, MovieClass movie)
        {
            command.Parameters.Clear();
            command.CommandText = "INSERT INTO MOVIES (TITLE, RELEASEDATE, GENRE, SUMMARY) " +
                                  "VALUES (@TITLE, @RELEASEDATE, @GENRE, @SUMMARY) " +
                                  "SELECT SCOPE_IDENTITY();";
            command.Parameters.Add("@TITLE", SqlDbType.VarChar, 100);
            command.Parameters.Add("@RELEASEDATE", SqlDbType.DateTime);
            command.Parameters.Add("@GENRE", SqlDbType.TinyInt);
            command.Parameters.Add("@SUMMARY", SqlDbType.VarChar, 250);
            command.Prepare();
            command.Parameters["@TITLE"].Value       = movie.t;
            command.Parameters["@RELEASEDATE"].Value = DBTypesEvaluator.ToDateTime(movie.rd);
            command.Parameters["@GENRE"].Value       = movie.g;
            command.Parameters["@SUMMARY"].Value     = movie.s;

            movie.i = DBTypesEvaluator.ToInteger(command.ExecuteScalar());
            if (movie.i != 0)
            {
                /* insert directors */
                inserDirectors(command, movie);

                /* insert actors */
                insertActors(command, movie);
            }
        }
Ejemplo n.º 3
0
        public void omdbApiTest()
        {
            OmdbRepo   repo   = new OmdbRepo();
            MovieClass result = repo.getMovie("john wick");

            Assert.IsNotNull(result);
        }
Ejemplo n.º 4
0
 public IActionResult Create([Bind("id,name,genre,releasedate,agerating,movierating")] MovieClass movieClass)
 {
     if (ModelState.IsValid)
     {
         movieClass.id = Guid.NewGuid();
         movies.Add(movieClass);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(movieClass));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a movie with the given paramaters.
 /// </summary>
 /// <param name="title">The films title</param>
 /// <param name="starring">Who stars in it</param>
 /// <param name="director">The director</param>
 /// <param name="duration">The duration of the movie formatted as {hh,mm,ss} </param>
 /// <param name="genre">The Genre</param>
 /// <param name="classification">The Classification</param>
 /// <param name="quantity">The number of the film in stock</param>
 public Movie(string title, string[] starring, string director, int[] duration, MovieGenre genre, MovieClass classification, int quantity)
 {
     this.quanitiy       = quantity;
     this.title          = title;
     this.starring       = starring;
     this.director       = director;
     this.duration       = duration;
     this.genre          = genre;
     this.classification = classification;
     timesBorrowed       = 0;
 }
        private MovieClass parseToMovieClass(OmdbClass omdbObj)
        {
            MovieClass returnObj = new MovieClass();

            returnObj.t  = omdbObj.Title;
            returnObj.rd = getReleasedDate(omdbObj.Released);
            returnObj.g  = getGenre(omdbObj.Genre);
            returnObj.s  = omdbObj.Plot;
            returnObj.md = Functions.stringToList(omdbObj.Director, ", ");
            returnObj.ma = Functions.stringToList(omdbObj.Actors, ", ");

            return(returnObj);
        }
Ejemplo n.º 7
0
        public async Task <MovieClass> GetMovieDetails(MovieClass e)
        {
            HtmlDocument _htmlDoc = new HtmlDocument();

            _htmlDoc.LoadHtml($"https://subscene.com/{e.Url}");
            var tes = $"https://subscene.com/{e.Url}";
            var responseSubtitles = await client.GetAsync(tes);

            var responseStringSubtiels = await responseSubtitles.Content.ReadAsStringAsync();

            _htmlDoc.LoadHtml(responseStringSubtiels);



            string ratingValue;
            string ratingCount;
            string downloadsCount;
            string downloadLink;

            try
            {
                ratingValue    = _htmlDoc.DocumentNode.SelectNodes("//*[@itemprop='ratingValue']").FirstOrDefault().ChildNodes.FirstOrDefault().InnerText;
                ratingCount    = _htmlDoc.DocumentNode.SelectNodes("//*[@itemprop='ratingCount']").FirstOrDefault().ChildNodes.FirstOrDefault().InnerText;
                downloadsCount = _htmlDoc.DocumentNode.SelectNodes("//*[@id='details']/ul/li[11]").FirstOrDefault().ChildNodes.ElementAt(2).InnerText;
                downloadLink   = _htmlDoc.DocumentNode.SelectNodes("//*[@class='download']").FirstOrDefault().ChildNodes.ElementAt(1).Attributes.FirstOrDefault().Value;
                downloadLink   = $"https://subscene.com/{downloadLink}";
            }
            catch
            {
                ratingValue    = string.Empty;
                ratingCount    = string.Empty;
                downloadsCount = string.Empty;
                downloadLink   = string.Empty;
            }


            downloadsCount = ClearEscapeSequences(downloadsCount);

            MovieClass movie = new MovieClass()
            {
                DownloadsCount = downloadsCount,
                DownloadLink   = downloadLink,
                Title          = e.Title,
                RatingValue    = ratingValue,
                RatingCount    = ratingCount,
                RelevanceScore = e.RelevanceScore,
                Url            = e.Url
            };

            return(movie);
        }
        private static void insertActors(SqlCommand command, MovieClass movie)
        {
            command.Parameters.Clear();
            command.CommandText = "INSERT INTO MOVIEACTORS VALUES (@MOVIEID, @ACTOR) ";
            command.Parameters.Add("@MOVIEID", SqlDbType.Int);
            command.Parameters.Add("@ACTOR", SqlDbType.VarChar, 50);
            command.Prepare();

            for (int i = 0; i < movie.ma.Count; i++)
            {
                command.Parameters["@MOVIEID"].Value = movie.i;
                command.Parameters["@ACTOR"].Value   = movie.ma[i];
                command.ExecuteNonQuery();
            }
        }
Ejemplo n.º 9
0
        public void ChangeMovie(MovieClass movie)
        {
            using (var connection = new SqlConnection(DatabaseClass.ConnectionString))
                using (var command = new SqlCommand())
                {
                    command.Connection  = connection;
                    command.CommandText = "";

                    connection.Open();

                    int affectedRows = command.ExecuteNonQuery();

                    if (affectedRows == 0)
                    {
                        throw new DatabaseException("Kon de gegevens niet in de database schrijven.");
                    }
                }
        }
Ejemplo n.º 10
0
        protected Task <bool> TaskImplementation(CancellationToken cancellationToken)
        {
            SqlConnection connection = new SqlConnection(ProjectVariables.dbConnectionString);

            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand();
                command.Connection = connection;

                /* read id of the last movie which it's data refreshed */
                int lastRefreshedId = DBFunctions.getLastRefreshedId(command);

                /* these movies will be refreshed from remote repository */
                List <MovieClass> movieList = DBFunctions.getMovieTitles(command, lastRefreshedId);

                MovieRepoFactory repoFactory = MovieRepoFactory.getInstance();
                IMovieRepo       repo        = repoFactory.getRepo(MovieRepoFactory.Repos.OMDB);

                int i = 0;
                for (i = 0; i < movieList.Count; i++)
                {
                    MovieClass oldMovie = movieList[i];
                    MovieClass newMovie = repo.getMovie(oldMovie.t);
                    newMovie.i = oldMovie.i;

                    DBFunctions.updateMovie(command, newMovie);
                    DBFunctions.updateLastRefreshedId(command, newMovie.i);
                }

                /* if all movies are refreshed, then start from the first one */
                if (i == 0)
                {
                    DBFunctions.updateLastRefreshedId(command, 0);
                }
            }
            catch (Exception ex)
            {
                Functions.LogWebMethodError(this.GetType().Name,
                                            System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
            }

            return(Task.FromResult <bool>(true));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Returns friendly strings for a movie classification
        /// </summary>
        /// <param name="m">the movie classification to friendlify</param>
        /// <returns>[long name, code]</returns>
        public static string[] FriendlyClassName(this MovieClass m)
        {
            switch ((int)m)
            {
            case 0:
                return(new string[] { "General", "G" });

            case 1:
                return(new string[] { "Parental Guidance", "PG" });

            case 2:
                return(new string[] { "Mature", "M15+" });

            case 3:
                return(new string[] { "Mature Accompanied", "MA15+" });

            default:
                return(new string[] { "Unknown", "NA" });
            }
        }
        public static void updateMovie(SqlCommand command, MovieClass movie)
        {
            command.Parameters.Clear();
            command.CommandText = "UPDATE MOVIES SET TITLE = @TITLE, RELEASEDATE = @RELEASEDATE, " +
                                  "GENRE = @GENRE, SUMMARY = @SUMMARY " +
                                  "WHERE ID = @ID ";
            command.Parameters.Add("@TITLE", SqlDbType.VarChar, 100);
            command.Parameters.Add("@RELEASEDATE", SqlDbType.DateTime);
            command.Parameters.Add("@GENRE", SqlDbType.TinyInt);
            command.Parameters.Add("@SUMMARY", SqlDbType.VarChar, 250);
            command.Parameters.Add("@ID", SqlDbType.Int);
            command.Prepare();
            command.Parameters["@TITLE"].Value       = movie.t;
            command.Parameters["@RELEASEDATE"].Value = DBTypesEvaluator.ToDateTime(movie.rd);
            command.Parameters["@GENRE"].Value       = movie.g;
            command.Parameters["@SUMMARY"].Value     = movie.s;
            command.Parameters["@ID"].Value          = movie.i;
            command.ExecuteNonQuery();

            // delete directories
            command.Parameters.Clear();
            command.CommandText = "DELETE FROM MOVIEDIRECTORS WHERE MOVIEID = @MOVIEID ";
            command.Parameters.Add("@MOVIEID", SqlDbType.Int);
            command.Prepare();
            command.Parameters["@MOVIEID"].Value = movie.i;
            command.ExecuteNonQuery();

            // delete actors
            command.Parameters.Clear();
            command.CommandText = "DELETE FROM MOVIEACTORS WHERE MOVIEID = @MOVIEID ";
            command.Parameters.Add("@MOVIEID", SqlDbType.Int);
            command.Prepare();
            command.Parameters["@MOVIEID"].Value = movie.i;
            command.ExecuteNonQuery();

            /* insert directors */
            inserDirectors(command, movie);

            /* insert actors */
            insertActors(command, movie);
        }
Ejemplo n.º 13
0
        public IActionResult Edit(Guid id, [Bind("id,name,genre,releasedate,agerating,movierating")] MovieClass movieClass)
        {
            if (id != movieClass.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var movieEdit = movies.Find(m => m.id == id);
                movieEdit.name        = movieClass.name;
                movieEdit.genre       = movieClass.genre;
                movieEdit.releasedate = movieClass.releasedate;
                movieEdit.agerating   = movieClass.agerating;
                movieEdit.movierating = movieClass.movierating;


                return(RedirectToAction(nameof(Index)));
            }
            return(View(movieClass));
        }
        public static List <MovieClass> getMovieTitles(SqlCommand command, int lastRefreshedId)
        {
            command.Parameters.Clear();
            command.CommandText = "SELECT TOP 50 * FROM MOVIES WHERE ID > @LASTREFRESHEDID ORDER BY ID ASC ";
            command.Parameters.Add("@LASTREFRESHEDID", SqlDbType.Int);
            command.Prepare();
            command.Parameters["@LASTREFRESHEDID"].Value = lastRefreshedId;

            List <MovieClass> list   = new List <MovieClass>();
            SqlDataReader     reader = command.ExecuteReader();

            while (reader.Read())
            {
                MovieClass movie = new MovieClass();
                movie.i = DBTypesEvaluator.ToInteger(reader["ID"]);
                movie.t = DBTypesEvaluator.ToString(reader["TITLE"]);

                list.Add(movie);
            }

            reader.Close();
            return(list);
        }
        public MovieClass getMovie(string title)
        {
            MovieClass returnObj = null;
            string     keyword   = title.Replace(' ', '+');
            string     apiText   = string.Format("?t={0}&apikey={1}", keyword, ProjectVariables.omdbApiKey);

            HttpResponseMessage response = client.GetAsync(apiText).Result;

            if (response.IsSuccessStatusCode)
            {
                string    result  = response.Content.ReadAsStringAsync().Result;
                OmdbClass omdbObj = JsonConvert.DeserializeObject <OmdbClass>(result);

                if (omdbObj == null || omdbObj.Title == null)
                {
                    return(null);
                }

                returnObj = parseToMovieClass(omdbObj);
            }

            return(returnObj);
        }
Ejemplo n.º 16
0
        public MovieClass MakeMovie(string title)
        {
            MovieClass Movie1;

            try
            {
                if (string.IsNullOrWhiteSpace(title))
                {
                    throw new ArgumentNullException(title, "tittle cannot be null or whitespace");
                }
                else
                {
                    return(new MovieClass()
                    {
                        Title = title
                    });
                }
            } //end of try block
            catch (ArgumentNullException ex)
            {
                MakeMovie("default");
            }
            catch (ArgumentException ex)
            {
                throw new Exception("not sure how it happened", ex);
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                Movie1 = new MovieClass(title);
                GC.Collect();
            }
            return(new MovieClass());
        }
Ejemplo n.º 17
0
 public void post([FromBody] MovieClass movie)
 {
     context.Movie.Add(movie);
     context.SaveChanges();
 }
Ejemplo n.º 18
0
        public JsonResult GetMovie(string userName, string password, string title)
        {
            GetMovieResult result     = new GetMovieResult();
            SqlConnection  connection = new SqlConnection(ProjectVariables.dbConnectionString);

            try
            {
                Functions.EnsureNotNullCredentials(userName, password);

                connection.Open();
                SqlCommand command = new SqlCommand();
                command.Connection = connection;

                bool flag = DBFunctions.checkLogin(command, userName, password);
                if (!flag)
                {
                    result.isErr = true;
                }
                else
                {
                    // get movie from cache if it is cached
                    MovieClass cacheMovie = null;
                    MovieClass movie      = null;
                    if (Functions.getCache <MovieClass>(cache, ProjectVariables.MOVIE_CACHE_TAG, out cacheMovie))
                    {
                        if (cacheMovie.t.Contains(title))
                        {
                            movie = cacheMovie;
                        }
                    }

                    // read movie from database
                    if (movie == null)
                    {
                        movie = DBFunctions.getMovie(command, title);
                    }

                    // get the movie from remote repositories
                    if (movie == null)
                    {
                        MovieRepoFactory repoFactory = MovieRepoFactory.getInstance();
                        IMovieRepo       repo        = repoFactory.getRepo(MovieRepoFactory.Repos.OMDB);

                        movie = repo.getMovie(title);
                        if (movie != null)
                        {
                            DBFunctions.insertMovie(command, movie);
                        }
                    }

                    // add to cache
                    if (movie != null)
                    {
                        Functions.setCache <MovieClass>(cache, ProjectVariables.MOVIE_CACHE_TAG, movie);
                    }

                    result.m = movie;
                }

                connection.Close();
            }
            catch (Exception ex)
            {
                result.isErr = true;
                Functions.LogWebMethodError(this.GetType().Name,
                                            System.Reflection.MethodBase.GetCurrentMethod().Name, ex);
            }

            return(Json(result));
        }
        public static MovieClass getMovie(SqlCommand command, string title)
        {
            MovieClass result = null;

            command.Parameters.Clear();
            command.CommandText = "SELECT TOP 1 * FROM MOVIES WHERE TITLE LIKE @TITLE ";
            command.Parameters.Add("@TITLE", SqlDbType.VarChar, 100);
            command.Prepare();
            command.Parameters["@TITLE"].Value = "%" + title + "%";

            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                result    = new MovieClass();
                result.i  = DBTypesEvaluator.ToInteger(reader["ID"]);
                result.t  = DBTypesEvaluator.ToString(reader["TITLE"]);
                result.rd = DBTypesEvaluator.ToFullTimeStr(reader["RELEASEDATE"]);
                result.g  = DBTypesEvaluator.ToInteger(reader["GENRE"]);
                result.s  = DBTypesEvaluator.ToString(reader["SUMMARY"]);
            }
            reader.Close();

            if (result != null)
            {
                /* read movie director names */
                command.Parameters.Clear();
                command.CommandText = "SELECT * FROM MOVIEDIRECTORS WHERE MOVIEID = @MOVIEID ";
                command.Parameters.Add("@MOVIEID", SqlDbType.Int);
                command.Prepare();
                command.Parameters["@MOVIEID"].Value = result.i;

                List <string> directorList = new List <string>();
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    directorList.Add(DBTypesEvaluator.ToString(reader["DIRECTOR"]));
                }

                reader.Close();
                result.md = directorList;

                /* read movie actor names */
                command.Parameters.Clear();
                command.CommandText = "SELECT * FROM MOVIEACTORS WHERE MOVIEID = @MOVIEID ";
                command.Parameters.Add("@MOVIEID", SqlDbType.Int);
                command.Prepare();
                command.Parameters["@MOVIEID"].Value = result.i;

                List <string> actorList = new List <string>();
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    actorList.Add(DBTypesEvaluator.ToString(reader["ACTOR"]));
                }

                reader.Close();
                result.ma = actorList;
            }

            return(result);
        }
Ejemplo n.º 20
0
 public void DeleteMovie([Microsoft.AspNetCore.Mvc.FromBody] MovieClass movie)
 {
     _repo.DeleteMovie(movie.Id);
 }
Ejemplo n.º 21
0
 public void ChangeMovie(MovieClass movie)
 {
     _repo.ChangeMovie(movie);
 }
Ejemplo n.º 22
0
        private MovieClass sut;        // Field for the movieclass object.

        public MovieTests()            //constructor for MovieTests
        {
            sut = new MovieClass();
        }
Ejemplo n.º 23
0
 public void DistributeMovie(MovieClass m)
 {
     Movies.Add(m);
 }
Ejemplo n.º 24
0
 public void put([FromBody] MovieClass movie)
 {
     context.Movie.Update(movie);
     context.SaveChanges();
 }
Ejemplo n.º 25
0
 public void ChangeMovie(MovieClass movie)
 {
     _context.ChangeMovie(movie);
 }
Ejemplo n.º 26
0
 public void TestMethod4()
 {
     MovieClass obj = new MovieClass();
 }