Пример #1
0
        public IActionResult AddToPlaylist(int id, string SelectedMoviePlaylist)
        {
            var userName = User.FindFirstValue(ClaimTypes.NameIdentifier);

            MoviePlaylist moviePlaylist = _applicationDbContext.MoviePlaylists
                                          .Include(x => x.UserMovie)
                                          //.ThenInclude(x => x.MoviePlaylist)
                                          .FirstOrDefault(x => x.Id.ToString() == SelectedMoviePlaylist);

            var userMovie = new UserMovie
            {
                MovieId         = id,
                MoviePlaylistId = Convert.ToInt32(SelectedMoviePlaylist),
            };

            var movieToplaylist = new MoviePlaylist
            {
                UserId = userName,
                Name   = SelectedMoviePlaylist,
                //UserMovie = model.MovieId
            };

            _applicationDbContext.UserMovies.Add(userMovie);
            _applicationDbContext.SaveChanges();

            return(RedirectToAction("IndexMovie", "Movie"));
        }
Пример #2
0
        public void Delete(int playlistId)
        {
            MoviePlaylist playlistToDelete = Get(playlistId);

            _context.MoviePlaylist.Remove(playlistToDelete);
            _context.MoviePlaylistCombo.RemoveRange(_context.MoviePlaylistCombo.Where(pl => pl.MoviePlaylistId == playlistId));
            _context.SaveChanges();
        }
Пример #3
0
        public void Edit(int id, MoviePlaylist playlist)
        {
            MoviePlaylist playlistToEdit = Get(id);

            if (playlistToEdit != null)
            {
                playlistToEdit.Naam    = playlist.Naam;
                playlistToEdit.Publiek = playlist.Publiek;
                _context.SaveChanges();
            }
        }
Пример #4
0
        public IActionResult Delete(int playlistId)
        {
            MoviePlaylist playlist          = _playlistService.Get(playlistId);
            MoviePlaylistDeleteViewModel vm = new MoviePlaylistDeleteViewModel
            {
                Id   = playlist.Id,
                Naam = playlist.Naam
            };

            return(View(vm));
        }
Пример #5
0
        public IActionResult Edit(MoviePlaylistEditViewModel model)
        {
            MoviePlaylist playlistToEdit = new MoviePlaylist
            {
                Naam    = model.Naam,
                Publiek = model.Publiek == "Publiek"
            };

            _playlistService.Edit(model.Id, playlistToEdit);
            return(RedirectToAction("Details", new { playlistId = model.Id }));
        }
Пример #6
0
        public IActionResult Create(MoviePlaylistCreateViewModel model)
        {
            var           userId   = User.FindFirstValue(ClaimTypes.NameIdentifier);
            MoviePlaylist playlist = new MoviePlaylist {
                Naam      = model.Naam,
                UserId    = userId ?? null,
                Zichtbaar = true,
                Publiek   = model.Publiek == "Publiek"
            };

            _playlistService.Insert(playlist);
            return(RedirectToAction("Details", new { playlistId = playlist.Id }));
        }
Пример #7
0
        public IActionResult Edit(int playlistId)
        {
            MoviePlaylist moviePlaylistFromDb = _playlistService.Get(playlistId);
            var           userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            MoviePlaylistEditViewModel vm = new MoviePlaylistEditViewModel {
                Id      = moviePlaylistFromDb.Id,
                Naam    = moviePlaylistFromDb.Naam,
                Publiek = moviePlaylistFromDb.Publiek ? "Publiek" : "Privé",
                IsCurrentUserOwnerOfPlaylist = moviePlaylistFromDb.UserId == userId
            };

            return(View(vm));
        }
Пример #8
0
 public void DeleteMovieFromPlaylist()
 {
     using (movieContext = new MovieContext())
     {
         Movie movie = new Movie("AAAA", 2000, 133, "US", 1, "ASDFD");
         bc.Add(movie);
         MoviePlaylist moviePlaylist = new MoviePlaylist(1, movie.Id);
         bc.Add(moviePlaylist);
         int playlistMovieCountBeforeDeleted = movieContext.MoviesPlaylists.Count();
         bc.DeleteMovieFromPlaylist(1, 1);
         movieContext.Movies.Remove(bc.GetMovie(movie.Id));
         movieContext.SaveChanges();
         int playlistMovieCountAfterDeleted = movieContext.MoviesPlaylists.Count();
         Assert.AreNotEqual(playlistMovieCountAfterDeleted, playlistMovieCountBeforeDeleted, "Тhe  movie in playlist is not deleted");
     }
 }
Пример #9
0
 /// <summary>
 /// Метод, извикващ се при натискане на поле за изображение 3
 /// </summary>
 /// <param name="sender">Обект, изпращащ събитието</param>
 /// <param name="e">Данни за събитието</param>
 private void pictureBox3_Click(object sender, EventArgs e)
 {
     if (!movie.IsLiked)
     {
         pictureBoxHeart.Image = Image.FromFile("otherResources\\heart1.png");
         movie.IsLiked         = true;
         bc.UpdateLike(movie);
         MoviePlaylist moviePlaylist = new MoviePlaylist(1, movie.Id);
         bc.Add(moviePlaylist);
     }
     else if (movie.IsLiked)
     {
         pictureBoxHeart.Image = Image.FromFile("otherResources\\heart2.png");
         movie.IsLiked         = false;
         bc.UpdateDislike(movie);
         bc.DeleteMovieFromPlaylist(1, movie.Id);
     }
 }
Пример #10
0
 public void TestAddMoviePlaylist()
 {
     using (movieContext = new MovieContext())
     {
         int   countMoviePlaylist = movieContext.MoviesPlaylists.Count();
         Movie movie = new Movie("AAAA", 2000, 133, "US", 1, "ASDFD");
         bc.Add(movie);
         Playlist playlist = new Playlist("Pop");
         bc.Add(playlist);
         MoviePlaylist moviePlaylist = new MoviePlaylist(playlist.Id, movie.Id);
         bc.Add(moviePlaylist);
         int countMoviePlaylist1 = movieContext.MoviesPlaylists.Count();
         movieContext.Movies.Remove(movie);
         movieContext.Playlists.Remove(playlist);
         movieContext.MoviesPlaylists.Remove(moviePlaylist);
         movieContext.SaveChanges();
         Assert.AreNotEqual(countMoviePlaylist, countMoviePlaylist1, "Not added value in MoviePlaylist");
     }
 }
Пример #11
0
        public IActionResult CreateMovieList(CreateMovieListViewModel model)
        {
            if (!TryValidateModel(model))
            {
                return(View(model));
            }

            var userName = User.FindFirstValue(ClaimTypes.NameIdentifier);

            var newPlaylist = new MoviePlaylist
            {
                Name   = model.Name,
                UserId = userName,
            };

            _applicationDbContext.MoviePlaylists.Add(newPlaylist);
            _applicationDbContext.SaveChanges();

            return(RedirectToAction("MyMovieIndex"));
        }
Пример #12
0
        public IActionResult Details(int playlistId)
        {
            MoviePlaylist       playlistFromDb = _playlistService.Get(playlistId);
            IEnumerable <Movie> moviesFromDb   = _movieService.GetMoviesByPlaylistId(playlistId);
            List <MoviePlaylistMoviesListViewModel> moviesList = new List <MoviePlaylistMoviesListViewModel>();

            foreach (var mov in moviesFromDb)
            {
                int ratingAvg = mov.RatingReviews != null && mov.RatingReviews.Where(r => r.MovieId == mov.Id).Select(r => r.Rating).Count() != 0 ?
                                mov.RatingReviews.Where(rat => rat.MovieId == mov.Id && rat.Rating > -1).Select(r => r.Rating).Sum()
                                / mov.RatingReviews.Where(rat => rat.MovieId == mov.Id && rat.Rating > -1).Count() : -1;

                int aantalGezien = mov.UserMovieGezienStatus != null?
                                   mov.UserMovieGezienStatus.Where(s => s.MovieId == mov.Id && s.MovieGezienStatus != null && s.MovieGezienStatusId == 2).Count() : 0;

                moviesList.Add(new MoviePlaylistMoviesListViewModel
                {
                    Id           = mov.Id,
                    Speelduur    = mov.Speelduur,
                    Titel        = mov.Titel,
                    Rating       = ratingAvg,
                    AantalGezien = aantalGezien
                });
            }

            MoviePlaylistDetailsListView vm = new MoviePlaylistDetailsListView {
                Movies    = moviesList,
                Naam      = playlistFromDb.Naam,
                Aantal    = _playlistService.AantalMoviesInPlaylist(playlistId),
                Id        = playlistFromDb.Id,
                Speelduur = _playlistService.TotaleSpeelduur(playlistId),
                Username  = playlistFromDb.User.UserName
            };

            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            vm.IsCurrentUserOwnerOfPlaylist = userId == playlistFromDb.UserId;

            return(View(vm));
        }
Пример #13
0
        /// <summary>
        /// Метод, зареждащ се при натискане на бутона за добавяне на филм в плейлист
        /// </summary>
        /// <param name="sender">Обект, изпращащ събитието</param>
        /// <param name="e">Данни на събитието</param>
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            List <MoviePlaylist> moviePlaylists = mb.GetAllMoviePlaylists();

            // checks if this movie already exists in this playlist
            if (currPlaylist == null)
            {
                MessageBox.Show("Изберете правилен плейлист!");
                return;
            }
            foreach (var mp in moviePlaylists)
            {
                if (movie.Id == mp.MovieId && currPlaylist.Id == mp.PlaylistId)
                {
                    string            message = $"Филмът {movie.MovieTitle} вече съществува в плейлист {currPlaylist.Name}!";
                    string            title   = "Добави филм";
                    MessageBoxButtons buttons = MessageBoxButtons.OK;
                    DialogResult      result  = MessageBox.Show(message, title, buttons);
                    this.Hide();
                    return;
                }
            }
            if (currPlaylist.Name == "Favourites")
            {
                movie.IsLiked = true;
            }
            MoviePlaylist newMovie = new MoviePlaylist(currPlaylist.Id, movie.Id);

            mb.Add(newMovie);
            string            message2 = $"Филмът {movie.MovieTitle} e добавен в {currPlaylist.Name}!";
            string            title2   = "Добави филм";
            MessageBoxButtons buttons2 = MessageBoxButtons.OK;
            DialogResult      result2  = MessageBox.Show(message2, title2, buttons2);

            this.Hide();
        }
Пример #14
0
 public MoviePlaylist Insert(MoviePlaylist playlist)
 {
     _context.MoviePlaylist.Add(playlist);
     _context.SaveChanges();
     return(playlist);
 }