public async Task <IActionResult> AddMovieToList(int movieId) { if (!_efMovieListRepository.DoesUserHaveLists(Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)))) { TempData["ErrorMessage"] = "Please create a list before trying to add a movie"; return(RedirectToAction("Index", "Home")); } AddMovieToListViewModel addMovieToListViewModel = new AddMovieToListViewModel { MovieToAdd = await _movieApiService.GetMovieByIdAsync(movieId), UsersMovieLists = _efMovieListRepository.GetAllListsForUser( Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier))), }; return(View(addMovieToListViewModel)); }
public async Task <IActionResult> AddMovieToList([Bind] AddMovieToListViewModel movieToListViewModel) { if (ModelState.IsValid) { if (_efMovieListRepository.IsDuplicate(movieToListViewModel.MovieId, movieToListViewModel.ListId)) { TempData["ErrorMessage"] = "This movie is already in the list"; return(View(new AddMovieToListViewModel { MovieToAdd = await _movieApiService.GetMovieByIdAsync(movieToListViewModel.MovieId), UsersMovieLists = _efMovieListRepository.GetAllListsForUser( Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier))), })); } if (_efMovieListRepository.IsFullList(movieToListViewModel.ListId)) { TempData["ErrorMessage"] = "This list is full"; return(View(new AddMovieToListViewModel { MovieToAdd = await _movieApiService.GetMovieByIdAsync(movieToListViewModel.MovieId), UsersMovieLists = _efMovieListRepository.GetAllListsForUser( Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier))), })); } Movie m = await _movieApiService.GetMovieByIdAsync(movieToListViewModel.MovieId); m.MovieListId = movieToListViewModel.ListId; _efMovieRepository.AddMovie(m); return(RedirectToAction("EditMovieList", "List", new { movieListId = movieToListViewModel.ListId }));//Eventually redirect to their own list } TempData["ErrorMessage"] = "Movie add attempt failed"; return(View(new AddMovieToListViewModel { MovieToAdd = await _movieApiService.GetMovieByIdAsync(movieToListViewModel.MovieId), UsersMovieLists = _efMovieListRepository.GetAllListsForUser( Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier))), })); }