public IActionResult About(int id) { var movie = _allMovies.GetComplete(id); var model = new MovieViewModel { AverageUserRating = movie.AverageUserRating, IMDBRating = movie.IMDBRating, RottenTomatoesRating = movie.RottenTomatoesRating, TomatoeImage = movie.TomatoeImage, Director = movie.Director, MovieId = id, Summary = movie.Plot, Genres = movie.Genres?.Select(g => g.Genre).ToList(), PosterUrl = movie.Poster, Title = movie.Title, Year = movie.Year, UserOpinion = new List <UserOpinionViewModel>() }; var relevantUserMovies = movie?.AddedByUsers?.Where(u => !string.IsNullOrEmpty(u.UserMovies.First().UserComment)) .Select(x => new { UserMovie = x.UserMovies.First(), UserName = x.UserName }); //What happens if relevantUserMovies is empty? foreach (var userMovie in relevantUserMovies) { model.UserOpinion.Add( new UserOpinionViewModel() { Rating = userMovie.UserMovie.UserRating, Added = userMovie.UserMovie.Added, Comment = userMovie.UserMovie.UserComment, UserName = userMovie.UserName }); } //Logged in var currentUserId = _userManager.GetUserId(HttpContext.User); if (currentUserId != null) { var userMovie = _userMovieData.Get(currentUserId, id); if (userMovie != null)//IsInList { model.IsFavorite = userMovie.Favored; model.IsHyped = userMovie.Hyped; model.IsInList = true; } } return(View(model)); }
public IActionResult EditUserMovie(int id) { var currentUserId = _userManager.GetUserId(HttpContext.User);// FindByIdAsync(userId); var userMovie = _userMovieData.Get(currentUserId, id); var viewModel = new UserMovieViewModel() { Movie = _sqlMovieData.GetComplete(userMovie.MovieId), Comment = userMovie.UserComment, Rating = userMovie.UserRating, IsFavorite = userMovie.Favored, IsHyped = userMovie.Hyped, Added = userMovie.Added }; return(View(viewModel)); }