//adds genre to genre table (for recommendations) public bool AddtoGenre(PopcornMovie popcornMovie) { try { //split genre value to get individual genres string genreString = popcornMovie.Genre.Replace(",", null); string[] genreArray = genreString.Split(" "); for (int i = 0; i < genreArray.Length; i++) { // Create a new genre object and fill in the details Genre newEntry = new Genre(); newEntry.Imdbid = popcornMovie.imdbID; newEntry.Genre1 = genreArray[i]; if (ModelState.IsValid) { //Add the new genre to the table _context.Genre.Add(newEntry); _context.SaveChanges(); } } return(true); } catch { return(false); } }
//selection from search result, second API call public async Task <IActionResult> MovieSelection(string id) { PopcornMovie movie1 = await _movieDAL.SecondGetMovieInfo($"{id}"); APIMovie movie2 = await _movieDAL.GetMovieInfo($"{id}"); APIPopVM selection = new APIPopVM(); selection.apiMovie = movie2; selection.popMovie = movie1; return(View(selection)); }
//add movie to list public async Task <IActionResult> AddtoWatchedList(string id) { // Get movie info from the API using the IMDB id PopcornMovie selectedMovie = await _movieDAL.SecondGetMovieInfo($"{id}"); // Get the login user id string loginUserId = User.FindFirst(ClaimTypes.NameIdentifier).Value; // Create a new UserMovie object and fill in the details UserMovie userMovie = new UserMovie(); userMovie.UserId = loginUserId; userMovie.MovieId = selectedMovie.imdbID; userMovie.Title = selectedMovie.Title; userMovie.Watched = false; userMovie.UserRating = 0; //Add the new object to the table if (ModelState.IsValid) { UserMovie userMovieExisting = _context.UserMovie.Where(um => um.MovieId == id && um.UserId == loginUserId).FirstOrDefault(); if (userMovieExisting == null) { TempData["MovieExistsCheck"] = "Successfully added!"; _context.UserMovie.Add(userMovie); _context.SaveChanges(); AddtoGenre(selectedMovie); AddToMovieActor(id, selectedMovie.Actors); AddToMovieDirector(id, selectedMovie.Director); AddToMovieYear(id, selectedMovie.Year); } else { TempData["MovieExistsCheck"] = "Movie already exists in your list!"; } } return(RedirectToAction("DisplayList")); }
public async Task <IActionResult> Index() { //maybe a dictionary with movie title and a list of ints Dictionary <string, int[]> userPop = new Dictionary <string, int[]>(); string userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; List <UserMovie> savedMovies = _context.UserMovie.Where(x => x.UserId == userId).ToList(); for (int i = 0; i < savedMovies.Count; i++) { PopcornMovie pop = new PopcornMovie(); pop = await MovieSelection($"{savedMovies[i].MovieId}"); int metaScore; bool isValid = int.TryParse(pop.Metascore, out metaScore); if (isValid == true) { int[] scores = new int[] { savedMovies[i].UserRating, metaScore }; userPop.Add(savedMovies[i].Title, scores); } } return(View(userPop)); }