Beispiel #1
0
        internal async Task <ObservableCollection <SavedMovie> > Recommend()
        {
            var user = User.GetInstance();
            var recommendedMovies = new ObservableCollection <SavedMovie>();
            var mostWatchedList   = await Task.Run(() => user.GetMostWatchedGenresAndYear());

            var baseString = DiscoverBase + "&release_date.gte=" + (mostWatchedList[3] - 5) +
                             "-01-01&release_date.lte=" + (mostWatchedList[3] + 5)
                             + "-12-12&with_genres=";


            using (var message = await _apiClient.GetAsync(baseString + mostWatchedList[0] + "%2C" + mostWatchedList[1] + "%2C" + mostWatchedList[2] + "%7C" +
                                                           mostWatchedList[0] + "%2C" + mostWatchedList[1]))
            {
                if (!message.IsSuccessStatusCode)
                {
                    return(recommendedMovies);
                }

                var root = await message.Content.ReadAsAsync <Root>();

                foreach (var t in root.results)
                {
                    var movie = new SavedMovie(0, await getInstance().GetMovie(t.id));
                    if (!User.GetInstance().Contains(movie))
                    {
                        recommendedMovies.Add(movie);
                    }
                }
            }

            return(recommendedMovies);
        }
Beispiel #2
0
        public void DeleteMovie(int id)
        {
            SavedMovie movieToDelete = UnitOfWork.SavedMoviesRepository.Get(id);

            UnitOfWork.SavedMoviesRepository.Remove(movieToDelete);
            UnitOfWork.Commit();
        }
        public RatedMovie(SavedMovie movie)
        {
            InitializeComponent();
            MovieStack.BindingContext = movie;
            this.movie = movie;
            Genres     = new ObservableCollection <Genre>(movie.genres);
            Title      = movie.title;

            BoxView.Background = ColorPallet.GetBackground();
            Task.Run(() => ColorPallet.AnimateBackground(BoxView));
            Carousel.ItemsSource = Genres;
        }
Beispiel #4
0
        public MovieJMDBApi Add(long userId, MovieJMDBApi movie)
        {
            // user mora da postoji
            var user = _uow.Users.FirstOrDefault(a => a.Id == userId, "");

            ValidationHelper.ValidateNotNull(user);

            // film mora postojati u bazi da bi se dodala asocijativna klasa, ako ne postoji dodajemo ga
            // film postoji ako vec ima taj ID

            var movieExist = _uow.MoviesJMDBApi.FirstOrDefault(a => a.Id == movie.Id, ""); // ovo je izgenerisan id iz jmdb APIa a ne iz nase baze!

            if (movieExist != null)
            {
                //provera da li je vec unet film za tog usera:
                var exist = _uow.SavedMovies.FirstOrDefault(f => f.UserId == userId && f.MovieJMDBApiId == movie.Id, "");
                ValidationHelper.ValidateEntityExists(exist);

                SavedMovie savedMovie = new SavedMovie
                {
                    UserId         = userId,
                    MovieJMDBApiId = movie.Id,
                    SavingDate     = DateTime.Now
                };

                var savedMovieAdded = _uow.SavedMovies.Add(savedMovie, "");
                _uow.Save();
            }
            else
            {
                //moramo da ga dodamo a nakon toga i asocijativnu klasu
                var newMovie = _uow.MoviesJMDBApi.Add(movie, "");
                _uow.Save();

                //provera da li je vec unet film za tog usera:
                var exist = _uow.SavedMovies.FirstOrDefault(f => f.UserId == userId && f.MovieJMDBApiId == movie.Id, "");
                ValidationHelper.ValidateEntityExists(exist);

                // ako nije dodajemo ga
                SavedMovie savedMovie = new SavedMovie
                {
                    UserId         = userId,
                    MovieJMDBApiId = movie.Id,
                    SavingDate     = DateTime.Now
                };

                _uow.SavedMovies.Add(savedMovie, "");
                _uow.Save();
            }
            return(movie);
        }
Beispiel #5
0
        public List <SavedMovie> LoadSavedMovies()
        {
            try
            {
                SqlConnection conn = OpenConnection();
                SqlCommand    cmd  = new SqlCommand("SELECT Movie.MovieID, Movie.Name FROM Movie, SavedMovie WHERE " +
                                                    "SavedMovie.UserID = 3 AND Movie.MovieID = SavedMovie.MovieID;", conn);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable      dt = new DataTable();
                da.Fill(dt);

                List <SavedMovie> lm = new List <SavedMovie>();

                foreach (DataRow dr in dt.Rows)
                {
                    SavedMovie movie = new SavedMovie
                    {
                        MovieID = int.Parse(dr["MovieID"].ToString()),
                        Name    = dr["Name"].ToString(),
                    };
                    lm.Add(movie);
                }
                return(lm);
            }
            catch (SqlException Sqle)
            {
                Console.WriteLine("Problema al cargar usuario");
                Console.WriteLine(Sqle.Message);
                return(null);
                //throw;
            }
            catch (Exception e)
            {
                Console.WriteLine("Problema no relacionado a Sql 2");
                Console.WriteLine(e.Message);
                return(null);
                //throw;
            }
            finally
            {
                CloseConnection();
            }
        }
Beispiel #6
0
 public void SavedMoview(String url, String errorMessage)
 {
     SavedMovie?.Invoke(this, new ListEventArgs(url, errorMessage));
 }
        public void AddSavedMovieSavedMovieExist()
        {
            var movieToAdd = new MovieJMDBApi
            {
                Id = "tt999",
                MovieDetailsJMDBApi = new MovieDetailsJMDBApi
                {
                    Actors   = "Actors",
                    Country  = "USA",
                    Director = "Director",
                    Duration = 111,
                    Genre    = "Action",
                    Name     = "Movie 99",
                    Year     = 2020
                },
                Name         = "Movie 99",
                Poster       = "poster 9",
                SavedUsers   = null,
                WatchedUsers = null
            };

            SavedMovie savedMovie = new SavedMovie
            {
                UserId         = 1,
                MovieJMDBApiId = "tt999",
                SavingDate     = DateTime.Now,
                User           = fakeUser,
                MovieJMDBApi   = new MovieJMDBApi
                {
                    Id = "tt999",
                    MovieDetailsJMDBApi = new MovieDetailsJMDBApi
                    {
                        Actors   = "Actors",
                        Country  = "USA",
                        Director = "Director",
                        Duration = 111,
                        Genre    = "Action",
                        Name     = "Movie 99",
                        Year     = 2020
                    },
                    Name       = "Movie 99",
                    Poster     = "poster 9",
                    SavedUsers = new List <SavedMovie> {
                        new SavedMovie {
                            MovieJMDBApi   = movieToAdd,
                            MovieJMDBApiId = "tt999",
                            SavingDate     = DateTime.Now,
                            User           = fakeUser,
                            UserId         = 1
                        }
                    },
                    WatchedUsers = null
                }
            };

            _uowMock.Setup(uow => uow.Users.FirstOrDefault(x => x.Id == 1, ""))
            .Returns(fakeUser);

            _uowMock.Setup(uow => uow.MoviesJMDBApi.FirstOrDefault(m => m.Id == movieToAdd.Id, ""))
            .Returns(movieToAdd);

            _uowMock.Setup(uow => uow.SavedMovies.FirstOrDefault(m => m.UserId == 1 && m.MovieJMDBApiId == movieToAdd.Id, ""))
            .Returns(savedMovie);


            Exception ex = Assert.Throws <ValidationException>(delegate { _manager.Add(1, movieToAdd); });

            Assert.That(ex.Message, Is.EqualTo("SavedMovie currently exists!"));
        }
        public void AddSavedMovieMovieJMDBApiNotExixstInDb()
        {
            var movieToAdd = new MovieJMDBApi
            {
                Id = "tt999",
                MovieDetailsJMDBApi = new MovieDetailsJMDBApi
                {
                    Actors   = "Actors",
                    Country  = "USA",
                    Director = "Director",
                    Duration = 111,
                    Genre    = "Action",
                    Name     = "Movie 99",
                    Year     = 2020
                },
                Name         = "Movie 99",
                Poster       = "poster 9",
                SavedUsers   = null,
                WatchedUsers = null
            };

            _uowMock.Setup(uow => uow.Users.FirstOrDefault(x => x.Id == 1, ""))
            .Returns(fakeUser);

            _uowMock.Setup(uow => uow.MoviesJMDBApi.FirstOrDefault(m => m.Id == movieToAdd.Id, ""))
            .Returns((MovieJMDBApi)null);

            _uowMock.Setup(uow => uow.MoviesJMDBApi.Add(movieToAdd, ""))
            .Returns(movieToAdd);

            _uowMock.Setup(uow => uow.SavedMovies.FirstOrDefault(m => m.UserId == 1 && m.MovieJMDBApiId == "tt999", ""))
            .Returns((SavedMovie)null);

            SavedMovie savedMovie = new SavedMovie
            {
                UserId         = 1,
                MovieJMDBApiId = movieToAdd.Id,
                SavingDate     = DateTime.Now
            };

            SavedMovie addedSavedMovie = new SavedMovie
            {
                UserId         = 1,
                MovieJMDBApiId = "tt999",
                SavingDate     = DateTime.Now,
                User           = fakeUser,
                MovieJMDBApi   = new MovieJMDBApi
                {
                    Id = "tt999",
                    MovieDetailsJMDBApi = new MovieDetailsJMDBApi
                    {
                        Actors   = "Actors",
                        Country  = "USA",
                        Director = "Director",
                        Duration = 111,
                        Genre    = "Action",
                        Name     = "Movie 99",
                        Year     = 2020
                    },
                    Name       = "Movie 99",
                    Poster     = "poster 9",
                    SavedUsers = new List <SavedMovie> {
                        new SavedMovie {
                            MovieJMDBApi   = movieToAdd,
                            MovieJMDBApiId = "tt999",
                            SavingDate     = DateTime.Now,
                            User           = fakeUser,
                            UserId         = 1
                        }
                    },
                    WatchedUsers = null
                }
            };

            _uowMock.Setup(uow => uow.SavedMovies.Add(savedMovie, ""))
            .Returns(addedSavedMovie);

            var result = _manager.Add(1, movieToAdd);

            // _uowMock.Verify(uow => uow.SavedMovies.Add(savedMovie, ""), Times.Once());
            _uowMock.Verify(uow => uow.MoviesJMDBApi.Add(movieToAdd, ""), Times.Once());
            _uowMock.Verify(uow => uow.Save(), Times.Exactly(2));

            Assert.AreEqual(movieToAdd.Id, result.Id);
            Assert.AreEqual(movieToAdd.MovieDetailsJMDBApi, result.MovieDetailsJMDBApi);
        }
        public void Setup()
        {
            _uowMock             = new Mock <IUnitOfWork>();
            _propertyMappingMock = new Mock <IPropertyMappingService>();
            _propertyCheckerMock = new Mock <IPropertyCheckerService>();

            _manager = new SavedMoviesManager(_propertyMappingMock.Object, _propertyCheckerMock.Object, _uowMock.Object);

            fakeUser = new User
            {
                Id       = 1,
                Name     = "user",
                Surname  = "user",
                Password = "******",
                Picture  = "picture",
                Email    = "email",
                NotificationsReceived = null,
                NotificationsSent     = null,
                FriendsReceived       = null,
                FriendsSent           = null,
                SavedMovies           = null,
                WatchedMovies         = null
            };

            fakeMovieJMDBApi = new MovieJMDBApi
            {
                Id = "tt123",
                MovieDetailsJMDBApi = new MovieDetailsJMDBApi
                {
                    Actors   = "actors",
                    Country  = "SRB",
                    Director = "Director",
                    Duration = 111,
                    Genre    = "comedy",
                    Name     = "Movie 1",
                    Year     = 2021
                },
                Name         = "Movie 1",
                Poster       = "poster 1",
                SavedUsers   = null,
                WatchedUsers = null
            };

            fakeSavedMovie = new SavedMovie
            {
                UserId         = 1,
                User           = fakeUser,
                MovieJMDBApiId = "tt123",
                MovieJMDBApi   = fakeMovieJMDBApi,
                SavingDate     = new DateTime(2020, 5, 5)
            };

            fakeListResult = new List <SavedMovie>
            {
                fakeSavedMovie,
                new SavedMovie
                {
                    UserId         = 1,
                    MovieJMDBApiId = "tt999",
                    SavingDate     = new DateTime(2020, 6, 6),
                    User           = fakeUser,
                    MovieJMDBApi   = new MovieJMDBApi
                    {
                        Id = "tt999",
                        MovieDetailsJMDBApi = new MovieDetailsJMDBApi
                        {
                            Actors   = "Actors",
                            Country  = "USA",
                            Director = "Director",
                            Duration = 111,
                            Genre    = "Action",
                            Name     = "Movie 99",
                            Year     = 2020
                        },
                        Name         = "Movie 99",
                        Poster       = "poster 9",
                        SavedUsers   = null,
                        WatchedUsers = null
                    }
                }
            };
        }