Ejemplo n.º 1
0
        public TMDbManager()
        {
            TMDbClient = new TMDbClient(ConfigurationManager.AppSettings["TheMovieDB"]);
            MongoManager = new MongoDBManager();

            TMDbClient.GetConfig();
            TMDbConfig config = TMDbClient.Config;
            ImageBase = config.Images.BaseUrl + config.Images.PosterSizes.Where(o => o == "w342").First();
            Client = new TMDbClient(ConfigurationManager.AppSettings["TheMovieDB"]);
        }
Ejemplo n.º 2
0
        public TMDbManager()
        {
            TMDbClient   = new TMDbClient(ConfigurationManager.AppSettings["TheMovieDB"]);
            MongoManager = new MongoDBManager();

            TMDbClient.GetConfig();
            TMDbConfig config = TMDbClient.Config;

            ImageBase = config.Images.BaseUrl + config.Images.PosterSizes.Where(o => o == "w342").First();
            Client    = new TMDbClient(ConfigurationManager.AppSettings["TheMovieDB"]);
        }
Ejemplo n.º 3
0
        public async Task<List<Movie>> GetRecommendedMovies(string userID)
        {
            MongoDBManager mm = new MongoDBManager();
            List<Movie> movies = new List<Movie>();

            Dictionary<ObjectId, int> similarMovies = new Dictionary<ObjectId, int>();
            UserInformation user = await mm.GetUserInformation(userID);

            if (user == null)
            {
                return movies;
            }

            foreach (var movieLike in user.MovieLikes)
            {
                List<UserInformation> users = mm.GetAllUsersWithExceptCurrent(userID,movieLike);

                foreach (var userFromDb in users)
                {
                    foreach (var movie in userFromDb.MovieLikes)
                    {
                        if (!similarMovies.ContainsKey(movie.Id))
                        {
                            similarMovies.Add(movie.Id,0);
                        }

                        similarMovies[movie.Id]++;
                    }
                }

            }

            var sortedSimilarMovies = from pair in similarMovies
                        orderby pair.Value descending 
                        select pair;

            int counter = 0;
            foreach (var sortedSimilarMovie in sortedSimilarMovies)
            {
                if (user.MovieLikes.Exists(x => x.Id == sortedSimilarMovie.Key))
                {
                    continue;
                }

                counter++;
                movies.Add(await mm.GetMovie(sortedSimilarMovie.Key));
            }

            return movies;
        }
Ejemplo n.º 4
0
        public async Task <ObjectId?> InsertMovieByName(string name)
        {
            MongoDBManager mm    = new MongoDBManager();
            var            found = await mm.FindMoviesByName(name);

            if (found.Count == 0)
            {
                SearchContainer <SearchMovie> results = Client.SearchMovie(name);
                if (results.TotalResults >= 1)
                {
                    SearchMovie tmdb  = results.Results.First();
                    var         movie = await ParseMovie(tmdb.Id);

                    await MongoManager.InsertNewMovie(movie);

                    return(movie.ID);
                }
            }
            return(null);
        }
Ejemplo n.º 5
0
        public async Task<ActionResult> Index(int? page)
        {
            MongoDBManager mm = new MongoDBManager();
            var movies = await mm.GetMovies();

            List<MovieListModel> listMovies = new List<MovieListModel>();

            foreach (var m in movies)
            {
                MovieListModel newMovie = new MovieListModel()
                {
                    AvgUserRating = m.AvgUserRating,
                    ID = m.ID,
                    Title = m.Title
                };
                var movie = await mm.GetMovie(m.ID);
                newMovie.Poster = movie.Poster;
                listMovies.Add(newMovie);
            }

            return View(listMovies.ToPagedList(page ?? 1, 12));
        }
Ejemplo n.º 6
0
        public async Task<ActionResult> DislikeMovie(string movieID)
        {
            ObjectId oid = new ObjectId(movieID);
            MongoDBManager mm = new MongoDBManager();
            await mm.DislikeMovie(User.Identity.GetUserId(), oid);

            return Json(string.Empty);
        }
Ejemplo n.º 7
0
        public async Task<ActionResult> UpdateUserRating(string movieID, int rating)
        {
            ObjectId oid = new ObjectId(movieID);
            MongoDBManager mm = new MongoDBManager();
            await mm.UpdateUserRating(User.Identity.GetUserId(), oid, rating);

            return Json(string.Empty);
        }
Ejemplo n.º 8
0
        public async Task<ActionResult> ShowMovieInformation(string id)
        {
            var oid = new ObjectId(id);
            MongoDBManager mm = new MongoDBManager();
            Movie movie = await mm.GetMovie(oid);
            var userRating = mm.GetUserRating(User.Identity.GetUserId(), oid);
            ShowMovieInformationViewModel model = new ShowMovieInformationViewModel()
            {
                ID = oid,
                Director = movie.Director,
                Actors = movie.Actors,
                Genres = movie.Genres,
                ImdbRating = movie.ImdbRating,
                TmdbRating = movie.TMDbRating,
                YouTube = movie.YouTube,
                Title = movie.Title,
                Runtime = movie.Runtime,
                Poster = movie.Poster,
                Plot = movie.Plot,
                Language = movie.Language,
                MetascoreRating = movie.MetascoreRating,
                Released = movie.Released.Value,                
                AvgUserRating = movie.AvgUserRating                         
            };

            if (userRating != null)
            {
                model.Liked = true;
                model.UserRating = userRating.UserRating;
            }
            
            return View(model);
        }
Ejemplo n.º 9
0
        public async Task<ActionResult> ShowUserMovies(int? page)
        {
            MongoDBManager mm = new MongoDBManager();
            UserInformation user = await mm.GetUserInformation(User.Identity.GetUserId());
            List<MovieListModel> movies = new List<MovieListModel>();

            if (user.MovieLikes != null)
            {
                foreach (var userMovie in user.MovieLikes)
                {
                    MovieListModel newMovie = new MovieListModel()
                    {
                        AvgUserRating = userMovie.UserRating,
                        ID = userMovie.Id,
                        Title = userMovie.Name
                    };
                    var movie = await mm.GetMovie(userMovie.Id);
                    newMovie.Poster = movie.Poster;
                    movies.Add(newMovie);
                }
            }

            return View(movies.ToPagedList(page ?? 1, 12));
        }
Ejemplo n.º 10
0
        //
        //show user information

        
       
        public async Task<ActionResult> ShowUserInformation()
        {
            MongoDBManager mm = new MongoDBManager();
            UserInformation user = await mm.GetUserInformation(User.Identity.GetUserId());
            ShowUserInformationViewModel model = new ShowUserInformationViewModel()
            {
                Birthday = user.Birthday,
                FirstName = user.FirstName,
                LastName = user.LastName,
                Email = user.Email
            };
            return View(model);
        }
Ejemplo n.º 11
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user, model.Password);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    // Get the information about the user from the external login provider
                    UserInformation facebookUser = new UserInformation()
                    {
                        Birthday = default(DateTime),
                        FirstName = "",
                        LastName = "",
                        Email = user.Email,
                        Id = user.Id
                    };
                    facebookUser.MovieLikes = new List<MovieLike>();

                    MongoDBManager mongoManager = new MongoDBManager();
                    mongoManager.InsertNewUser(facebookUser);
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    return RedirectToAction("Index", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Ejemplo n.º 12
0
        public ActionResult UpdateTweets()
        {
            MongoDBManager mm = new MongoDBManager();
            mm.InsertNewTweets();

            return View("ShowTweets", mm.GetAllTweets());
        }
Ejemplo n.º 13
0
        public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return RedirectToAction("Index", "Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();
                
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                var result = await UserManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);
                    if (result.Succeeded)
                    {
                        
                        var fb = new FacebookClient(Session["tokenFB"].ToString());
                        dynamic data = new System.Dynamic.ExpandoObject();
                        data.FirstName = "";
                        data.LastName = "";
                        data.Birthday = default(DateTime);
                        data.movies = null;
                        //data.Birthday = "";
                        data = fb.Get("/me?fields=first_name,last_name,email,birthday,movies");
                        UserInformation facebookUser = new UserInformation()
                        {
                            Birthday = DateTime.ParseExact(data.birthday, "MM/dd/yyyy", CultureInfo.InvariantCulture),
                            //Birthday = data.Birthday,
                            FirstName = data.first_name,
                            LastName = data.last_name,
                            Email = model.Email,
                            Id = user.Id
                        };
                        facebookUser.MovieLikes = new List<MovieLike>();
                        if (data.movies != null)
                        {
                            foreach (dynamic movie in data.movies.data)
                            {
                                TMDbManager movieManager = new TMDbManager();
                                MongoDBManager mm = new MongoDBManager();
                                var exists = await mm.FindMoviesByName((string)movie.name);
                                ObjectId? movieId = null;
                                if (exists.Count >= 1)
                                {
                                    movieId = exists.First().ID;
                                }
                                else
                                {
                                    movieId = await movieManager.InsertMovieByName(movie.name);
                                }
                                if (movieId != null)
                                {
                                    facebookUser.MovieLikes.Add(new MovieLike() { Id = movieId.Value, Name = movie.name });
                                }
                            }
                        }
                        
                        MongoDBManager mongoManager = new MongoDBManager();
                        mongoManager.InsertNewUser(facebookUser);
                        await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                        return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
Ejemplo n.º 14
0
        public async Task<ActionResult> LikeMovie(string movieID)
        {
            ObjectId oid = new ObjectId(movieID);
            System.Diagnostics.Debug.WriteLine(movieID);
            MongoDBManager mm = new MongoDBManager();
            await mm.LikeMovie(User.Identity.GetUserId(), oid);

            return Json(string.Empty);
        }
Ejemplo n.º 15
0
 public async Task<ObjectId?> InsertMovieByName(string name)
 {
     MongoDBManager mm = new MongoDBManager();
     var found = await mm.FindMoviesByName(name);
     if (found.Count == 0)
     {
         SearchContainer<SearchMovie> results = Client.SearchMovie(name);
         if (results.TotalResults >= 1)
         {
             SearchMovie tmdb = results.Results.First();
             var movie = await ParseMovie(tmdb.Id);
             await MongoManager.InsertNewMovie(movie);
             return movie.ID;
         }
     }
     return null;
 }
Ejemplo n.º 16
0
        public async Task<ActionResult> UpdateUserLikes(IndexViewModel model, int? page)
        {
            if (Session["tokenFB"] != null)
            {
                MongoDBManager mm = new MongoDBManager();
                List<MovieLike> movies = await mm.UpdateUserLikes(User.Identity.GetUserId(), Session["tokenFB"].ToString());
                return View("ShowUserMovies",movies);
            }
            else
            {
                return View("ShowUserMovies", (new List<MovieLike>()).ToPagedList(page ?? 1, 12));
            }

        }
        public async Task<List<Movie>> GetRecommendedMovies(string userID)
        {
            MongoDBManager mm = new MongoDBManager();
            List<Movie> movies = new List<Movie>();

            Dictionary<string,int> genras = new Dictionary<string, int>();
            UserInformation user = await mm.GetUserInformation(userID);

            if (user == null)
            {
                return movies;
            }


            /*foreach (var movieLike in user.MovieLikes) //get user favourite genra
            {
                var movie = mm.GetMovie(movieLike.Id);
                List<string> movieGenras = movie.Genre.Split(',').Select(x => x.Trim()).ToList();

                if (parameters.Valid(movieGenras))
                {
                    movies.Add(movie);
                }


            }
            return movies;*/
            foreach (var movieLike in user.MovieLikes)//get user favourite genra
            {
                var movie = await mm.GetMovie(movieLike.Id);
                List<string> movieGenras = movie.Genres;

                foreach (var movieGenra in movieGenras)
                {
                    if (!genras.ContainsKey(movieGenra))
                    {
                        genras.Add(movieGenra,0);
                    }
                    genras[movieGenra]++;
                }
            }

            var max = genras.Values.Max();
            string favouriteGenre = "";

            foreach (var genre in genras.Keys)
            {
                if (genras[genre] == max)
                {
                    favouriteGenre = genre;
                    break;
                }
            }

            movies = mm.GetMoviesWithGenre(favouriteGenre);
            List<Movie> moviesWithoutUserLiked = new List<Movie>();

            foreach (var movie in movies)
            {
                bool exist = false;
                foreach (var userLiked in user.MovieLikes)
                {
                    if (userLiked.Id == movie.ID)
                    {
                        exist = true;
                        break;
                    }
                }

                if (!exist)
                {
                    moviesWithoutUserLiked.Add(movie);
                }
            }

            MoviesSort ms = new MoviesSort();

            moviesWithoutUserLiked.Sort(ms);
            return moviesWithoutUserLiked;

        }
Ejemplo n.º 18
0
 public ActionResult ShowTweets()
 {
     MongoDBManager mm = new MongoDBManager();
     return View("ShowTweets", mm.GetAllTweets());
 }
        public async Task<List<Movie>> GetRecommendedMovies(string userID)
        {
            MongoDBManager mm = new MongoDBManager();
            List<Movie> movies = new List<Movie>();

            Dictionary<string, int> actors = new Dictionary<string, int>();
            UserInformation user = await mm.GetUserInformation(userID);

            if (user == null)
            {
                return movies;
            }


            foreach (var movieLike in user.MovieLikes)//get user favourite genra
            {
                var movie = await mm.GetMovie(movieLike.Id);
                List<string> movieActors = movie.Actors;

                foreach (var movieActor in movieActors)
                {
                    if (!actors.ContainsKey(movieActor))
                    {
                        actors.Add(movieActor, 0);
                    }
                    actors[movieActor]++;
                }
            }

            var max = actors.Values.Max();
            string favouriteActor = "";

            foreach (var actor in actors.Keys)
            {
                if (actors[actor] == max)
                {
                    favouriteActor = actor;
                    break;
                }
            }

            movies = await mm.GetMoviesWithActor(favouriteActor);
            List<Movie> moviesWithoutUserLiked = new List<Movie>();

            foreach (var movie in movies)
            {
                bool exist = false;
                foreach (var userLiked in user.MovieLikes)
                {
                    if (userLiked.Id == movie.ID)
                    {
                        exist = true;
                        break;
                    }
                }

                if (!exist)
                {
                    moviesWithoutUserLiked.Add(movie);
                }
            }

            MoviesSort ms = new MoviesSort();

            moviesWithoutUserLiked.Sort(ms);
            return moviesWithoutUserLiked;
        }