Esempio n. 1
0
        /// <summary>
        /// Allows to change name of film if we click on proper column in dataGridView1
        /// </summary>
        /// <param name="moviename">Movie name we want to check for.</param>
        /// <param name="filename">File name of the file we want to change</param>

        public static void MovieNameChange(string moviename, string filename)
        {
            try{
                MovieDatabaseEntities db = new MovieDatabaseEntities();

                var CurrentUserID = MainApplicationWindow.getCurrentUserID();
                var result        = db.Favourite_Hated.SingleOrDefault(o => o.MainMovieList.File_Name == filename && o.UserID == CurrentUserID);


                if (result.Movie_Name != moviename && result.UserID == CurrentUserID)
                {
                    result.Movie_Name = moviename;
                    db.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            { //In case of error while adding stuff to database
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
        /// <summary>
        /// Adds all checkboxes to Add_Movie_To_Playlist_Panel for each playlist
        /// </summary>
        public void AddAllPlaylistCheckBoxes(Movies movie)
        {
            MovieDatabaseEntities db = new MovieDatabaseEntities();
            var UserID = MainApplicationWindow.getCurrentUserID();

            currentMovie = movie;

            var numberOfPlaylists =
                (from user in db.Users
                 where user.UserID == UserID
                 select user.Number_Of_Playlists).FirstOrDefault();

            for (int i = 0; i < numberOfPlaylists; i++)
            {
                createPlaylistCheckbox(i, movie);
            }

            foreach (MonoFlat_CheckBox checkBox in Add_Movie_To_Playlist_Panel.Controls)
            {
                foreach (Playlist playlist in db.Playlists)
                {
                    if (playlist.FilmID == movie.MovieID && playlist.UserID == UserID && playlist.PlaylistID == (int)checkBox.Tag)
                    {
                        checkBox.Checked = true;
                    }
                }
            }
        }
        private void Accept_Button_Click(object sender, EventArgs e)
        {
            MovieDatabaseEntities db = new MovieDatabaseEntities();
            var userID = MainApplicationWindow.getCurrentUserID();
            var usr    = db.Users.SingleOrDefault(o => o.UserID == userID);


            foreach (MonoFlat_CheckBox checkbox in Add_Movie_To_Playlist_Panel.Controls)
            {
                if (checkbox.Checked)
                {
                    var playlist = db.Playlists.SingleOrDefault(o => o.UserID == userID && o.FilmID == currentMovie.MovieID && o.PlaylistID == (int)checkbox.Tag);

                    if (playlist == null)
                    {
                        Methods.AddToPlaylist((int)checkbox.Tag, usr.Username, currentMovie.File_Name);
                    }
                }
                else
                {
                    Methods.RemoveFromPlaylist(currentMovie, (int)checkbox.Tag);
                }
            }
            this.Close();
        }
        /// <summary>
        /// Create checkbox in PlaylistsManagement form
        /// </summary>
        /// <param name="i">Number of user's playlists</param>
        /// <param name="movie">Movie that we want to add to playlists</param>
        public void createPlaylistCheckbox(int i, Movies movie)
        {
            MovieDatabaseEntities db = new MovieDatabaseEntities();
            var userID = MainApplicationWindow.getCurrentUserID();

            var pl =
                (from playlist in db.List_Of_Playlists
                 where playlist.UserID == userID && playlist.ID == i + 1
                 select playlist).FirstOrDefault();

            if (pl != null)
            {
                if (Add_Movie_To_Playlist_Panel.Controls.Count == 0)
                {
                    MonoFlat_CheckBox checkBox = new MonoFlat_CheckBox();
                    checkBox.Margin   = new System.Windows.Forms.Padding(3, 0, 3, 0);
                    checkBox.Width    = Add_Movie_To_Playlist_Panel.Width - 30;
                    checkBox.Height   = 20;
                    checkBox.Text     = pl.Playlist_Name;
                    checkBox.Location = new Point(0, 0);
                    int tag = i + 1;
                    checkBox.Tag = tag;
                    Add_Movie_To_Playlist_Panel.Controls.Add(checkBox);
                }
                else
                {
                    int maxi = 0;
                    foreach (MonoFlat_CheckBox chb in Add_Movie_To_Playlist_Panel.Controls)
                    {
                        if (Int32.Parse(chb.Tag.ToString()) > maxi)
                        {
                            maxi = Int32.Parse(chb.Tag.ToString());
                        }
                    }

                    foreach (MonoFlat_CheckBox item in Add_Movie_To_Playlist_Panel.Controls)
                    {
                        if (item.Tag.Equals(maxi))
                        {
                            MonoFlat_CheckBox prevCheckBox = item;

                            MonoFlat_CheckBox checkBox = new MonoFlat_CheckBox();
                            checkBox.Margin   = new System.Windows.Forms.Padding(3, 0, 3, 0);
                            checkBox.Width    = Add_Movie_To_Playlist_Panel.Width - 30;
                            checkBox.Height   = 20;
                            checkBox.Text     = pl.Playlist_Name;
                            checkBox.Location = new Point(0, prevCheckBox.Bounds.Bottom + 6);
                            int tag = i + 1;
                            checkBox.Tag = tag;
                            Add_Movie_To_Playlist_Panel.Controls.Add(checkBox);
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Adds a movie to database taking into consideration all possible exceptions
        /// </summary>
        /// <param name="FileName">Name of the movie filename</param>
        public static void AddMovie(string FilePath)
        { //Adds a movie id, movie name and movie path to database
            try
            {
                string FileName = System.IO.Path.GetFileNameWithoutExtension(FilePath);

                MovieDatabaseEntities db       = new MovieDatabaseEntities();
                MainMovieList         objMovie = new MainMovieList();

                if (db.MainMovieLists.Any(o => o.File_Name == FileName))
                {
                    Console.WriteLine(FileName + " is already in the MainMovieList table");
                }
                else
                {
                    objMovie.File_Name = FileName;
                    objMovie.File_Path = FilePath;
                    db.MainMovieLists.Add(objMovie);
                    db.SaveChanges();
                }

                int usrId = MainApplicationWindow.getCurrentUserID();
                Console.WriteLine("Current username: "******"\n");

                if (db.Favourite_Hated.Any(o => o.FilmID == objMovie.ID && o.UserID == usrId))
                {
                    Console.WriteLine(FileName + " is already in the Favourite_Hated table");
                }
                else
                {
                    Console.WriteLine("Adding " + FileName + " to the Favourite_Hated table for user with id: " + usrId);
                    User usr     = new User();
                    var  searchs = db.Users.SingleOrDefault(o => o.UserID == usrId);
                    AddFavouriteOrHated(-1, searchs.Username, FileName);
                }
                //Jezeli nie dasz sobie rady ze stworzeniem query: stworz funckje foreach i sprawdz czy dany film ma konkretny usrname i filmid
            }
            catch (DbEntityValidationException e)
            { //In case of error while adding stuff to database
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Removes record from Playlist in db with specified userID and filmID
        /// </summary>
        /// <param name="film">film that has to be removed from Playlist for current user</param>
        public static void RemoveFromPlaylist(Movies film, int playlistID)
        {
            var userID = MainApplicationWindow.getCurrentUserID();
            MovieDatabaseEntities db = new MovieDatabaseEntities();

            var queryPlaylist = from Playlist in db.Playlists
                                where Playlist.UserID == userID &&
                                Playlist.FilmID == film.MovieID &&
                                Playlist.PlaylistID == playlistID
                                select Playlist;

            foreach (var del in queryPlaylist)
            {
                db.Playlists.Remove(del);
            }
            db.SaveChanges();
        }
Esempio n. 7
0
        /// <summary>
        /// Set information to be displayed in dataGridView1 after clicking "Playlist" button
        /// </summary>
        /// <returns>Return list of movies to add to dataGridView1</returns>
        public static List <Movies> AddItemToPlaylist(int tag)
        {
            int UserID = MainApplicationWindow.getCurrentUserID();

            MovieDatabaseEntities db = new MovieDatabaseEntities();

            var movieQuery = from fh in db.Favourite_Hated
                             join p in db.Playlists on new { ID = fh.FilmID } equals new { ID = p.FilmID }
            where (p.UserID == fh.UserID && p.UserID == UserID && p.PlaylistID == tag)
            select new Movies
            {
                MovieID       = (int)fh.MainMovieList.ID,
                Movie_Name    = fh.Movie_Name,
                File_Name     = fh.MainMovieList.File_Name,
                LikeOrDislike = fh.LikeOrDislike == 1 ? "Favourite" : (fh.LikeOrDislike == 0 ? "Hated" : ""),
                Path          = fh.MainMovieList.File_Path
            };

            List <Movies> movieList = movieQuery.ToList();

            return(movieList);
        }
Esempio n. 8
0
        /// <summary>
        /// Set information to be displayed in dataGridView1
        /// </summary>
        /// <returns>Return list of movies to add to dataGridView1</returns>
        public static List <Movies> AddItemToList()
        {
            int UserID = MainApplicationWindow.getCurrentUserID();

            MovieDatabaseEntities db = new MovieDatabaseEntities();

            var movieQuery = from mml in db.MainMovieLists
                             join fh in db.Favourite_Hated on new { ID = mml.ID } equals new { ID = fh.FilmID } into fh_join
            from fh in fh_join.DefaultIfEmpty()
            where
            fh.UserID == UserID
                select new Movies
            {
                MovieID       = mml.ID,
                Movie_Name    = fh.Movie_Name,
                File_Name     = mml.File_Name,
                LikeOrDislike = fh.LikeOrDislike == 1 ? "Favourite" : (fh.LikeOrDislike == 0 ? "Hated" : ""),
                Path          = mml.File_Path
            };

            List <Movies> movieList = movieQuery.ToList();

            return(movieList);
        }
Esempio n. 9
0
 private void Accept_Button_Click(object sender, EventArgs e)
 {
     MainApplicationWindow.changeNameOfPlaylist(monoFlat_TextBox1.Text);
     this.Close();
 }