public int CreateMovieList(MovieListDTO movieListDTO)
        {
            MovieListDTO movieList = new MovieListDTO();

            movieList = movieListDTO;
            return(movieList.Id);
        }
        public List <MovieListDTO> GetAllMovieListByUserId(int UserId)
        {
            List <MovieListDTO> movieListDTOsInDataBase = new List <MovieListDTO>();
            List <MovieListDTO> retrievedMovieListDTOs  = new List <MovieListDTO>();
            MovieListDTO        movieListDTO1           = new MovieListDTO();
            MovieListDTO        movieListDTO2           = new MovieListDTO();
            MovieListDTO        movieListDTO3           = new MovieListDTO();

            //set some names and id
            movieListDTO1.Name   = "TestList1";
            movieListDTO1.Id     = 1;
            movieListDTO1.UserId = 1;
            movieListDTO2.Name   = "TestList2";
            movieListDTO2.Id     = 2;
            movieListDTO2.UserId = 1;
            movieListDTO3.Name   = "TestList3";
            movieListDTO3.Id     = 3;
            movieListDTO3.UserId = 2;
            //add them to the list
            movieListDTOsInDataBase.Add(movieListDTO1);
            movieListDTOsInDataBase.Add(movieListDTO2);
            movieListDTOsInDataBase.Add(movieListDTO3);
            foreach (MovieListDTO movieListDTO in movieListDTOsInDataBase)
            {
                if (movieListDTO.UserId == UserId)
                {
                    retrievedMovieListDTOs.Add(movieListDTO);
                }
            }
            return(retrievedMovieListDTOs);
        }
예제 #3
0
        public List <MovieListDTO> GetAllMovieListByUserId(int UserId)
        {
            List <MovieListDTO> movieListDTOs = new List <MovieListDTO>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    string     query = "SELECT * FROM MovieList WHERE UserId = @UserId;";
                    SqlCommand getMovieListByUserId = new SqlCommand(query, conn);
                    getMovieListByUserId.Parameters.AddWithValue("@UserId", UserId);
                    conn.Open();
                    var reader = getMovieListByUserId.ExecuteReader();
                    while (reader.Read())
                    {
                        MovieListDTO movieListDTO = new MovieListDTO();
                        movieListDTO.Id         = reader.GetInt32(0);
                        movieListDTO.Name       = reader.GetString(1);
                        movieListDTO.MovieCount = reader.GetInt32(2);
                        movieListDTO.UserId     = reader.GetInt32(3);
                        movieListDTOs.Add(movieListDTO);
                        //movieListDTOs.Add(GetMovieList(Convert.ToInt32(reader["MLID"])));
                    }
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e);
            }
            return(movieListDTOs);
        }
예제 #4
0
        public int CreateMovieList(MovieListDTO movieListDTO)
        {
            int createdMovieId = 0;

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    string query = "INSERT INTO MovieList (Name, MovieCount, UserId)";
                    query += " VALUES (@Name, @MovieCount, @UserId)";
                    query += " SELECT CAST (scope_identity() AS int)";
                    SqlCommand createMovieList = new SqlCommand(query, conn);
                    createMovieList.Parameters.AddWithValue("@Name", movieListDTO.Name);
                    createMovieList.Parameters.AddWithValue("@MovieCount", 0);
                    createMovieList.Parameters.AddWithValue("@UserId", movieListDTO.UserId);
                    conn.Open();
                    createdMovieId = Convert.ToInt32(createMovieList.ExecuteScalar());
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e);
            }
            return(createdMovieId);
        }
예제 #5
0
 public void Update(MovieListDTO movieListDTO)
 {
     try
     {
         using (SqlConnection conn = new SqlConnection(connectionString))
         {
             string query = "SELECT * FROM MovieList";
             query += " UPDATE MovieList SET Name = @Name";
             query += " , MovieCount = @MovieCount";
             query += " , UserId = @UserId";
             query += " Where Id = @Id";
             SqlCommand updateMovieListCommand = new SqlCommand(query, conn);
             conn.Open();
             updateMovieListCommand.Parameters.AddWithValue("@Name", movieListDTO.Name);
             updateMovieListCommand.Parameters.AddWithValue("@MovieCount", movieListDTO.MovieCount);
             updateMovieListCommand.Parameters.AddWithValue("@UserId", movieListDTO.UserId);
             updateMovieListCommand.Parameters.AddWithValue("@Id", movieListDTO.Id);
             updateMovieListCommand.ExecuteNonQuery();
         }
     }
     catch (SqlException e)
     {
         Console.WriteLine(e);
     }
 }
예제 #6
0
        public List <MovieListDTO> GetAllMovieLists()
        {
            List <MovieListDTO> movieListDTOs = new List <MovieListDTO>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    string     query            = "SELECT * FROM MovieList";
                    SqlCommand getAllMovieLists = new SqlCommand(query, conn);
                    conn.Open();
                    var reader = getAllMovieLists.ExecuteReader();
                    while (reader.Read())
                    {
                        MovieListDTO movieListDTO = new MovieListDTO();
                        movieListDTO.Id         = reader.GetInt32(0);
                        movieListDTO.Name       = reader.GetString(1);
                        movieListDTO.MovieCount = reader.GetInt32(2);
                        movieListDTO.UserId     = reader.GetInt32(3);
                        movieListDTOs.Add(movieListDTO);
                    }
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e);
            }
            return(movieListDTOs);
        }
예제 #7
0
        public IActionResult MovieListDeleteMovie(int movieId, int movieListID)
        {
            MovieList    movieList    = movieListCollection.GetMovieList(movieListID);
            MovieListDTO movieListDTO = movieListDTOFromMovieBO(movieList);

            movieList.RemoveMovieFromList(movieListID, movieId, movieListDTO);
            return(RedirectToAction("MovieListDetails", "MovieList", new { movieListId = movieListID }));
        }
예제 #8
0
        public MovieList GetMovieList(int id)
        {
            MovieListDTO movieListDTO = movieListCollDall.GetMovieList(id);
            MovieList    movieList    = new MovieList(movieListDTO);

            movieList.moviesIds = movieListCollDall.GetAllMovieListMoviesIDs(movieList.Id);
            return(movieList);
        }
예제 #9
0
        public IActionResult AddMovieToList(int movieId, int movieListId)
        {
            MovieListModel movieListModel = MovieListModelFromBO(movieListCollection.GetMovieList(movieListId));
            MovieListDTO   movieListDTO   = CreateMovieListDTOFromViewModel(movieListModel);
            MovieList      movieList      = new MovieList(movieListDTO);

            movieList.AddMovieToList(movieListDTO, movieId);
            return(RedirectToAction("EditMovieList", new { movieListId = movieListId }));
        }
예제 #10
0
        private MovieListDTO movieListDTOFromMovieBO(MovieList movieList)
        {
            MovieListDTO movieListDTO = new MovieListDTO();

            movieListDTO.Name       = movieList.Name;
            movieListDTO.Id         = movieList.Id;
            movieListDTO.UserId     = movieList.UserId;
            movieListDTO.MovieCount = movieList.MovieCount;
            return(movieListDTO);
        }
예제 #11
0
 public void AddMovieToList(MovieListDTO movieListDTO, int newMovieId)
 {
     if (CheckIfMovieIsAllreadyPresent(newMovieId, Movies) == false)
     {
         if (movieListDAL.AddMovieToList(movieListDTO.Id, newMovieId) == true && newMovieId != 3009)
         {
             movieListDTO.MovieCount++;
             Update(movieListDTO);
         }
     }
 }
예제 #12
0
        public MovieListDTO GetMovieList(int Id)
        {
            MovieListDTO movieListDTO = new MovieListDTO();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    //Things to select from the MovieList_Movies Connection Table:
                    string query = "SELECT MovieList_Movies.MovieList_Id";
                    //Things to select from the MovieTest Table:
                    query += ", MovieTest.Id AS MID, MovieTest.Name AS MName, MovieTest.Genre, MovieTest.Genre2, MovieTest.Date, MovieTest.Watched";
                    //Things to select from the MovieList Table:
                    query += ", MovieList.Id MLID, MovieList.Name AS MLName, MovieList.MovieCount, MovieList.UserId AS MLUID";
                    //Table To Select from:
                    query += " FROM MovieList_Movies";
                    //First Join:
                    query += " INNER JOIN MovieTest ON MovieList_Movies.Movie_Id= MovieTest.Id";
                    //Second Join:
                    query += " INNER JOIN MovieList ON MovieList_Movies.MovieList_Id = MovieList.Id";
                    //Set The Id:
                    query += " WHERE MovieList_Id = @MovieList_Id;";
                    SqlCommand getMovieList = new SqlCommand(query, conn);
                    getMovieList.Parameters.AddWithValue("@MovieList_Id", Id);
                    conn.Open();
                    var reader = getMovieList.ExecuteReader();
                    //Get the MovieList Data
                    if (reader.Read())
                    {
                        //The "X.ID" were given an alias to prevent "SqlException: out of range"
                        movieListDTO.Id         = Convert.ToInt32(reader["MLID"]);
                        movieListDTO.Name       = reader["MLName"].ToString();
                        movieListDTO.MovieCount = Convert.ToInt32(reader["MovieCount"]);
                        movieListDTO.UserId     = Convert.ToInt32(reader["MLUID"]);
                        while (reader.Read())
                        {
                            MovieDTO movieDTO = new MovieDTO();
                            movieDTO.ID       = Convert.ToInt32(reader["MID"]);
                            movieDTO.Name     = reader["MName"].ToString();
                            movieDTO.Genre    = reader["Genre"].ToString();
                            movieDTO.GenreTwo = reader["Genre2"].ToString();
                            movieDTO.Date     = reader["Date"].ToString();
                            movieDTO.Watched  = Convert.ToBoolean(reader["Watched"]);
                            movieListDTO.Movies.Add(movieDTO);
                        }
                    }
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e);
            }
            return(movieListDTO);
        }
예제 #13
0
        public async Task <MovieListDTO> Update(MovieListDTO movieList)
        {
            var updateMovieList = _context.MovieLists.FirstOrDefault(_ => _.Id == movieList.Id);

            updateMovieList.Name = movieList.Name;

            _context.MovieLists.Update(updateMovieList);
            await _context.SaveChangesAsync();

            return(MovieListDTO.Populate(updateMovieList));
        }
예제 #14
0
 //removes a movie from a single list
 public void RemoveMovieFromList(int movieListId, int movieId, MovieListDTO movieListDTO)
 {
     if (movieListDAL.RemoveMovieFromList(movieListId, movieId) == true)
     {
         if (movieId != 3009)
         {
             movieListDTO.MovieCount--;
         }
         Update(movieListDTO);
     }
 }
예제 #15
0
        public IActionResult CreateMovieList(MovieListModel movieListModel, string userName)
        {
            int userId = userCollection.GetUserIdByUName(userName);

            movieListModel.UserId = userId;
            MovieListDTO movieListDTO   = CreateMovieListDTOFromViewModel(movieListModel);
            MovieList    movielist      = new MovieList(movieListDTO);
            int          newMovieListId = movieListCollection.CreateMovieList(CreateMovieListDTOFromViewModel(movieListModel));

            movieListDTO.Id = newMovieListId;
            movielist.AddMovieToList(movieListDTO, 3009);
            return(RedirectToAction("Index", "MovieList", new { userName = userName }));
        }
예제 #16
0
 //constructor
 public MovieList(MovieListDTO movieListDTO)
 {
     this.Name         = movieListDTO.Name;
     this.MovieCount   = movieListDTO.MovieCount;
     this.Id           = movieListDTO.Id;
     this.UserId       = movieListDTO.UserId;
     this.movieListDAL = FactoryMovieListDAL.CreateMovieListDAL();
     foreach (MovieDTO movieDTO in movieListDTO.Movies)
     {
         Movie movie = new Movie(movieDTO);
         Movies.Add(movie);
     }
 }
예제 #17
0
        private MovieListDTO CreateMovieListDTOFromViewModel(MovieListModel movieListModel)
        {
            MovieListDTO movieListDTO = new MovieListDTO();

            movieListDTO.Id         = movieListModel.Id;
            movieListDTO.UserId     = movieListModel.UserId;
            movieListDTO.MovieCount = movieListModel.MovieCount;
            movieListDTO.Name       = movieListModel.Name;
            foreach (MovieModel moviemodel in movieListModel.movieModels)
            {
                movieListDTO.Movies.Add(movieDTOFromMovieModel(moviemodel));
            }
            return(movieListDTO);
        }
예제 #18
0
        public MovieListDTO Get()
        {
            var movies = movieDbRepository.GetWatchLaterByUserId(int.Parse(this.User.Claims.First().Value))
                         .Select(x => new MovieDetailDto()
            {
                MovieId = x.MovieId, Name = x.Name, Summary = x.Summary, Actors = x.MovieActors.Select(y => y.Actor), Genres = x.MovieGenres.Select(y => y.Genre), ReleaseYear = x.ReleaseYear, Rating = x.Ratings.Average(y => y.Score), Watched = x.WatchLaters.Any(y => y.MovieId == x.MovieId), ImageUrl = x.ImageUrl
            });

            var data = new MovieListDTO {
                Data = movies
            };

            return(data);
        }
        public void CreateMovieListTest_CreateAMovieListAndCheckIfAnIdIsReturned_ShouldBeTrue()
        {
            //assign
            IMovieListCollectionDAL movieListCollectionDALTest = new MovieListCollectionDALTEST();
            MovieListCollection     movieListCollection        = new MovieListCollection(movieListCollectionDALTest);
            MovieListDTO            movieListDTO = new MovieListDTO();

            movieListDTO.Id = 777;
            int movieListId;

            //act
            movieListId = movieListCollection.CreateMovieList(movieListDTO);
            //assert
            Assert.IsTrue(movieListId == movieListDTO.Id);
        }
예제 #20
0
        public MovieListDTO GetMovies(int page = 0, string orderBy = "", string name = "")
        {
            orderBy = WebUtility.UrlDecode(orderBy);
            name    = WebUtility.UrlDecode(name);

            if (orderBy.StartsWith("Rating"))
            {
                if (orderBy.EndsWith("DESC"))
                {
                    var movies = movieDbRepository.GetMoviesByRatingDescending(page, name)
                                 .Select(x => new MovieDetailDto()
                    {
                        MovieId = x.MovieId, Name = x.Name, Summary = x.Summary, Actors = x.MovieActors.Select(y => y.Actor), Genres = x.MovieGenres.Select(y => y.Genre), ReleaseYear = x.ReleaseYear, Rating = x.Ratings.Count > 0 ? x.Ratings.Average(y => y.Score) : -1, Watched = false, ImageUrl = x.ImageUrl, Runtime = x.Runtime
                    });
                    var data = new MovieListDTO {
                        Data = movies, Page = page, Total = movies.Count()
                    };
                    return(data);
                }
                else
                {
                    var movies = movieDbRepository.GetMoviesByRatingAscending(page, name)
                                 .Select(x => new MovieDetailDto()
                    {
                        MovieId = x.MovieId, Name = x.Name, Summary = x.Summary, Actors = x.MovieActors.Select(y => y.Actor), Genres = x.MovieGenres.Select(y => y.Genre), ReleaseYear = x.ReleaseYear, Rating = x.Ratings.Count > 0 ? x.Ratings.Average(y => y.Score) : -1, Watched = false, ImageUrl = x.ImageUrl, Runtime = x.Runtime
                    });
                    var data = new MovieListDTO {
                        Data = movies, Page = page, Total = movies.Count()
                    };
                    return(data);
                }
            }
            else
            {
                var movies = movieDbRepository.GetMovies(orderBy, page, name)
                             .Select(x => new MovieDetailDto()
                {
                    MovieId = x.MovieId, Name = x.Name, Summary = x.Summary, Actors = x.MovieActors.Select(y => y.Actor), Genres = x.MovieGenres.Select(y => y.Genre), ReleaseYear = x.ReleaseYear, Rating = x.Ratings.Count > 0 ? x.Ratings.Average(y => y.Score) : -1, Watched = false, ImageUrl = x.ImageUrl, Runtime = x.Runtime
                });


                var data = new MovieListDTO {
                    Data = movies, Page = page, Total = movies.Count()
                };

                return(data);
            }
        }
예제 #21
0
        public async Task <ActionResult <ReplyData> > GetMovies()
        {
            try
            {
                var response = new ReplyData();
                var data     = await _context.Movies.ToListAsync();

                response.data = _mapper.Map <List <Movie>, List <MovieListDTO> >(data);
                MovieListDTO p = new MovieListDTO();
                response.schema = new Schema(p, _context);
                return(response);
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to load data"));
            }
        }
예제 #22
0
        public async Task <MovieListDTO> Insert(MovieListDTO movieList)
        {
            var newMovieList = new MovieList
            {
                Name = movieList.Name,
                User = new User
                {
                    Id   = movieList.User.Id,
                    Name = movieList.User.Name,
                }
            };

            _context.MovieLists.Add(newMovieList);
            await _context.SaveChangesAsync();

            return(MovieListDTO.Populate(newMovieList));
        }
예제 #23
0
        public IActionResult GetMovieList()
        {
            var movieList = contex.Movie.ToList();
            var dtoList   = new List <MovieListDTO>();

            foreach (var item in movieList)
            {
                var dto = new MovieListDTO
                {
                    titulo        = item.titulo,
                    imagen        = item.imagen,
                    fechaCreacion = item.fechaCreacion
                };
                dtoList.Add(dto);
            }

            return(Ok(dtoList));
        }
예제 #24
0
        public async Task <MovieListDTO> RemoveMovie(MovieListDTO movieList, MovieDTO movie)
        {
            var updateMovieList = _context.MovieLists.Include("Movies").FirstOrDefault(_ => _.Id == movieList.Id);

            if (updateMovieList.Movies != null)
            {
                var removeMovie = updateMovieList.Movies.FirstOrDefault(_ => _.ImdbId == movie.ImdbId);

                if (removeMovie != null)
                {
                    updateMovieList.Movies.Remove(removeMovie);
                    _context.MovieLists.Update(updateMovieList);
                    await _context.SaveChangesAsync();
                }
            }

            return(MovieListDTO.Populate(updateMovieList));
        }
        public MovieListDTO GetMovieList(int Id)
        {
            int          moviestoAdd  = 10;
            MovieListDTO movieListDTO = new MovieListDTO();

            movieListDTO.Name   = "Test movieListDTO";
            movieListDTO.Id     = 1;
            movieListDTO.UserId = 1;
            List <MovieDTO> movieDTOs = new List <MovieDTO>();

            for (int i = 0; i < moviestoAdd; i++)
            {
                MovieDTO movieDTO = new MovieDTO();
                movieDTO.Name = $"MovieDTOTest{i}";
                movieDTO.ID   = i;
                movieDTOs.Add(movieDTO);
            }
            movieListDTO.Movies = movieDTOs;
            return(movieListDTO);
        }
        public List <MovieListDTO> GetAllMovieLists()
        {
            List <MovieListDTO> movielistDTOs = new List <MovieListDTO>();
            MovieListDTO        movieListDTO1 = new MovieListDTO();
            MovieListDTO        movieListDTO2 = new MovieListDTO();
            MovieListDTO        movieListDTO3 = new MovieListDTO();

            movieListDTO1.Name   = "TestList1";
            movieListDTO1.Id     = 1;
            movieListDTO1.UserId = 1;
            movieListDTO2.Name   = "TestList2";
            movieListDTO2.Id     = 2;
            movieListDTO2.UserId = 1;
            movieListDTO3.Name   = "TestList3";
            movieListDTO3.Id     = 3;
            movieListDTO3.UserId = 2;
            movielistDTOs.Add(movieListDTO1);
            movielistDTOs.Add(movieListDTO2);
            movielistDTOs.Add(movieListDTO3);
            return(movielistDTOs);
        }
예제 #27
0
        public async Task <MovieListDTO> AddMovie(MovieListDTO movieList, MovieDTO movie)
        {
            var updateMovieList = _context.MovieLists.Include("Movies").FirstOrDefault(_ => _.Id == movieList.Id);

            var movieAlreadyAdded = false;

            if (updateMovieList.Movies != null)
            {
                movieAlreadyAdded = updateMovieList.Movies.Any(_ => _.ImdbId == movie.ImdbId);
            }

            if (!movieAlreadyAdded)
            {
                var addMovie = new Movie
                {
                    ImdbId    = movie.ImdbId,
                    PosterUrl = movie.PosterUrl,
                    Release   = movie.Release,
                    Title     = movie.Title
                };
                _context.Movies.Add(addMovie);
                await _context.SaveChangesAsync();

                if (updateMovieList.Movies == null)
                {
                    updateMovieList.Movies = new List <Movie>();
                }

                updateMovieList.Movies.Add(addMovie);
                _context.MovieLists.Update(updateMovieList);

                await _context.SaveChangesAsync();
            }

            return(MovieListDTO.Populate(updateMovieList));
        }
예제 #28
0
        public List <MovieListDTO> GetAll()
        {
            var movieLists = _context.MovieLists.ToList();

            return(movieLists.Select(_ => MovieListDTO.Populate(_)).ToList() ?? new List <MovieListDTO>());
        }
예제 #29
0
        public MovieListDTO Get(Guid id)
        {
            var movieList = _context.MovieLists.FirstOrDefault(_ => _.Id == id);

            return(MovieListDTO.Populate(movieList) ?? new MovieListDTO());
        }
예제 #30
0
 //methods
 public void Update(MovieListDTO movieListDTO)
 {
     movieListDAL.Update(movieListDTO);
 }