示例#1
0
        // GET: MovieController
        public async Task <ActionResult> Index([FromQuery] QueryParams searchQueryParams)
        {
            string searchString = string.Empty;
            int    pageIndex    = 1;
            int    itemsPerPage = Constants.ITEMS_PER_PAGE;

            if (searchQueryParams != null)
            {
                searchString = searchQueryParams.SearchString;
                pageIndex    = searchQueryParams.PageNumber;
                itemsPerPage = searchQueryParams.ItemsPerPage ?? itemsPerPage;
            }
            var paginatedMovies = await _mediator.Send(new GetPaginatedMoviesQuery(searchString, pageIndex, itemsPerPage));

            var movieIndexViewModel = new MovieIndexViewModel
            {
                Movies         = _mapper.Map <List <MovieViewModel> >(paginatedMovies.AsEnumerable <Movie>()),
                PaginationInfo = new ViewModels.PaginationInfoViewModel
                {
                    PageIndex       = paginatedMovies.PageIndex,
                    ItemsPerPage    = paginatedMovies.ItemsPerPage,
                    TotalPages      = paginatedMovies.TotalPages,
                    HasNextPage     = paginatedMovies.HasNextPage,
                    HasPreviousPage = paginatedMovies.HasPreviousPage
                },
                SearchString = searchString
            };

            return(View(movieIndexViewModel));
        }
        public async Task Index_ShouldReturnPartialViewWhenAjaxRequestAndValidMovieId()
        {
            // Arrange
            Mock <IMovieDbService> movieDbService = new Mock <IMovieDbService>();

            movieDbService
            .Setup(ms => ms.GetMovieDetailsAsync(It.IsAny <int>()))
            .ReturnsAsync(new MovieDetailsServiceModel()
            {
                Id = FirstMovieId, Title = FirstMovieTitle, ProductionYear = FirstMovieProductionYear
            });

            HomeController controller = new HomeController(
                movieDbService.Object, null, null, null, null, null, null, null);

            controller.InjectAjaxRequest(true);

            // Act
            IActionResult actionResult = await controller.Index(FirstMovieId);

            // Assert
            actionResult.Should().BeOfType <PartialViewResult>();

            object model = actionResult.As <PartialViewResult>().Model;

            model.Should().BeOfType <MovieIndexViewModel>();

            MovieIndexViewModel returnedModel = model.As <MovieIndexViewModel>();

            returnedModel.MovieDetails.Id.Should().Be(FirstMovieId);
        }
        // GET: Movies
        // Requires using Microsoft.AspNetCore.Mvc.Rendering;
        public async Task <IActionResult> Index(string movieGenre, string searchString)
        {
            // Use LINQ to get list of genres.
            IQueryable <string> genreQuery = from m in _context.Genres
                                             orderby m.Name
                                             select m.Name;

            var movies = from m in _context.Movies
                         select m;

            if (!String.IsNullOrEmpty(searchString))
            {
                movies = movies.Where(s => s.Title.Contains(searchString));
            }

            if (!String.IsNullOrEmpty(movieGenre))
            {
                movies = movies.Where(x => x.Genre.Name == movieGenre);
            }

            var movieIndexVM = new MovieIndexViewModel
            {
                Genres = new SelectList(await genreQuery.Distinct().ToListAsync()),
                Movies = await movies
                         .Include(m => m.Genre)
                         .ToListAsync(),
                SearchString = searchString
            };

            return(View(movieIndexVM));
        }
        private void GetSearchResults(MovieIndexViewModel indexViewModel)
        {
            indexViewModel.searchMovieModel = new List <MovieSearch>();

            TMDbClient client = new TMDbClient(ConfigurationManager.AppSettings["TMDbKey"]);
            SearchContainer <SearchMovie> movieApiResults = client.SearchMovieAsync(indexViewModel.searchModel.Title).Result;

            if (movieApiResults.TotalResults >= 1)
            {
                foreach (var movie in movieApiResults.Results)
                {
                    MovieSearch localMovie = new MovieSearch
                    {
                        Id          = movie.Id,
                        Title       = movie.Title,
                        ReleaseDate = movie.ReleaseDate,
                        ImageUrl    = "http://image.tmdb.org/t/p/w185/" + movie.PosterPath
                    };

                    indexViewModel.searchMovieModel.Add(localMovie);
                }
            }
            else
            {
                MovieSearch noResultsMovie = new MovieSearch
                {
                    Id          = 0,
                    Title       = "No Title",
                    ReleaseDate = DateTime.Now,
                    ImageUrl    = "http://image.tmdb.org/t/p/w185/"
                };

                indexViewModel.searchMovieModel.Add(noResultsMovie);
            }
        }
        public ActionResult Index(MovieIndexViewModel indexViewModel)
        {
            GetPopularMovies(indexViewModel);
            GetSearchResults(indexViewModel);

            return(View(indexViewModel));
        }
        public ActionResult Index()
        {
            MovieIndexViewModel indexViewModel = new MovieIndexViewModel();

            GetPopularMovies(indexViewModel);

            return(View(indexViewModel));
        }
        /** List movies */
        public ActionResult Index()
        {
            var viewModel = new MovieIndexViewModel
            {
                Movies = movies
            };

            return(View(viewModel));
        }
示例#8
0
        public IActionResult Index()
        {
            List <Movie>        movies = movieCollection.GetMovies();
            MovieIndexViewModel model  = new MovieIndexViewModel();

            model.Movies = movies;

            return(View(model));
        }
        public ActionResult Movies()
        {
            var MovieIndexView = new MovieIndexViewModel()
            {
                Movies = _dbContext.Movies.ToList()
            };

            return(View(MovieIndexView.Movies));
        }
示例#10
0
        // GET: Movies
        public async Task <IActionResult> Index()
        {
            var movies  = from m in _context.Movies select m;
            var movieVm = new MovieIndexViewModel()
            {
                Films = await movies.ToListAsync()
            };

            return(View(movieVm));
        }
示例#11
0
        public ActionResult Index()
        {
            var movies = _context.Movies.Include(m => m.Genre).ToList();

            var viewModel = new MovieIndexViewModel()
            {
                MovieList = movies
            };

            return(View(viewModel));
        }
示例#12
0
        public ActionResult Index()
        {
            var movies = _context.Movies.Include(c => c.Genre).Take(100).ToList();

            var model = new MovieIndexViewModel
            {
                Movies = movies.ToList()
            };

            return(View(model));
        }
        public async Task Index_ShouldReturnCorrectViewModelWhenNotAjaxRequest()
        {
            // Arrange
            var allMovies = new List <MovieBaseServiceModel>()
            {
                new MovieBaseServiceModel()
                {
                    Id = FirstMovieId, ProductionYear = FirstMovieProductionYear, Title = FirstMovieTitle
                },
                new MovieBaseServiceModel()
                {
                    Id = SecondMovieId, ProductionYear = SecondMovieProductionYear, Title = SecondMovieTitle
                },
                new MovieBaseServiceModel()
                {
                    Id = ThirdMovieId, ProductionYear = ThirdMovieProductionYear, Title = ThirdMovieTitle
                }
            };

            Mock <IMovieDbService> movieDbService = new Mock <IMovieDbService>();

            movieDbService
            .Setup(ms => ms.GetAllMoviesAsync())
            .ReturnsAsync(allMovies);

            movieDbService
            .Setup(ms => ms.GetMovieDetailsAsync(It.IsAny <int>()))
            .ReturnsAsync(new MovieDetailsServiceModel()
            {
                Id = FirstMovieId, Title = FirstMovieTitle, ProductionYear = FirstMovieProductionYear
            });

            HomeController controller = new HomeController(
                movieDbService.Object, null, null, null, null, null, null, null);

            controller.InjectAjaxRequest(false);

            // Act
            IActionResult actionResult = await controller.Index(FirstMovieId);

            // Assert
            actionResult.Should().BeOfType <ViewResult>();

            object model = actionResult.As <ViewResult>().Model;

            model.Should().BeOfType <MovieIndexViewModel>();

            MovieIndexViewModel returnedModel = model.As <MovieIndexViewModel>();

            returnedModel.AllMovies.Should().Match(m => m.As <List <MovieBaseServiceModel> >().Count() == 3);
            returnedModel.MovieDetails.Should().Match(m => m.As <MovieDetailsServiceModel>().Id == FirstMovieId);
        }
示例#14
0
        public async Task <ActionResult> Index()
        {
            var model = new MovieIndexViewModel
            {
                Movies = await _dataContext.Movies
                         .OrderByDescending(movie => movie.AverageRating)
                         .Take(25)
                         .Project().To <MovieIndexViewModel.Movie>()
                         .ToListAsync()
            };

            return(View(model));
        }
示例#15
0
        // GET: Movies
        public IActionResult Index()
        {
            var genres = this.genresServices.GetAll();

            var vm = new MovieIndexViewModel
            {
                Genres  = new SelectList(genres, "Id", "Name"),
                GenreId = 0,
                SelectMovieResultViewModel = this.UpdateMovieIndexViewModel()
            };

            return(View(vm));
        }
        // GET: Movies
        public IActionResult Index(MovieIndexViewModel movieViewModel)
        {
            movieViewModel.Movies = _context.Movie.Include(m => m.Genre).Include(m => m.Director).Include(m => m.MoviesActors).ToList();

            if (movieViewModel.SearchString != null)
            {
                var movies = movieViewModel.Movies;

                movieViewModel.Movies = movies.Where(m => m.Name.ToLower().Contains(movieViewModel.SearchString.ToLower())).ToList();
            }

            return(View(movieViewModel));
        }
示例#17
0
        public async Task <IActionResult> Index()
        {
            var movies  = (from m in _context.Movies orderby m.Modified descending select m).Take(5);
            var shows   = from m in _context.Shows orderby m.StartTime where m.StartTime.Date == DateTime.Today && m.StartTime > DateTime.Now select m;
            var rooms   = from m in _context.Rooms select m;
            var movieVm = new MovieIndexViewModel()
            {
                Films     = await movies.ToListAsync(),
                ShowTimes = await shows.ToListAsync(),
                Rooms     = await rooms.ToListAsync()
            };

            return(View(movieVm));
        }
示例#18
0
        public ActionResult FilterMovies(string Title)
        {
            List <Movie> movies = _logic.GetMovies();

            MovieIndexViewModel viewModel = new MovieIndexViewModel
            {
                Account = _userSession.GetSession,
                Movies  = _logic.Filtermovie(movies, Title)
            };

            if (viewModel.Movies.Count == 0)
            {
                viewModel.Message = "No movies found";
            }
            return(View("Index", viewModel));
        }
示例#19
0
 public ActionResult Index()
 {
     if (HttpContext.Session.GetObject <Account>("User") != null)
     {
         MovieIndexViewModel viewModel = new MovieIndexViewModel
         {
             Account = HttpContext.Session.GetObject <Account>("User"),
             Movies  = _context.GetMovies()
         };
         return(View(viewModel));
     }
     else
     {
         return(View("NotLoggedIn"));
     }
 }
示例#20
0
        public ActionResult FilterMovies(string Title)
        {
            List <Movie> movies = _context.GetMovies();

            MovieIndexViewModel viewModel = new MovieIndexViewModel
            {
                Account = HttpContext.Session.GetObject <Account>("User"),
                Movies  = _context.Filtermovie(movies, Title)
            };

            if (viewModel.Movies.Count == 0)
            {
                viewModel.Message = "No movies found";
            }
            return(View("Index", viewModel));
        }
示例#21
0
        // GET: Movie
        public ActionResult Index(string T, int Y)
        {
            //Creates an object out of the view model, you can find it in Models/Database/Movies
            MovieIndexViewModel model = new MovieIndexViewModel();
            //Fetches a movie object from database
            Movie movieObject = db.Movies.Where(m => m.Title == T && m.ReleaseYear == Y).Select(m => m).First();
            //Fetches list of reviews from database
            var movieReviews = db.Reviews.Where(r => r.MovieID == movieObject.ID).Select(r => r).ToList();

            //Adds the movie object into the view model object
            model.Movie = movieObject;
            //Adds the list of reviews into the view model object
            model.Reviews = movieReviews;
            //Passes the view model object into the view
            return(View(model));
        }
示例#22
0
        public ActionResult Index(int? page, string sort, bool? desc)
        {
            if (page == null || page < 0) page = 1;
            if (String.IsNullOrWhiteSpace(sort)) sort = "Title";
            if (desc == null) desc = false;

            var vm = new MovieIndexViewModel
            {
                SortBy = sort,
                SortDesc = desc.Value,
                CurrentPage = page.Value,
                ItemsPerPage = 20,
                DataSource = _movieRepository.All
            };

            return View(vm);
        }
示例#23
0
 public ActionResult Index(string Message)
 {
     if (_userSession.GetSession != null)
     {
         MovieIndexViewModel viewModel = new MovieIndexViewModel
         {
             Account = _userSession.GetSession,
             Movies  = _logic.GetMovies(),
             Message = Message,
         };
         return(View(viewModel));
     }
     else
     {
         return(View("NotLoggedIn"));
     }
 }
示例#24
0
        public IActionResult MoviesPage(string id)
        {
            List <Movie>        movies = new List <Movie>();
            MovieIndexViewModel model  = new MovieIndexViewModel();

            if (!String.IsNullOrEmpty(id))
            {
                movies = movieCollection.GetMovies().Where(s => s.MovieTitle.Contains(id)).ToList();
            }
            else
            {
                movies = movieCollection.GetMovies();
            }

            model.Movies = movies;

            return(View(model));
        }
示例#25
0
        public IActionResult Index()
        {
            MovieIndexViewModel model = new MovieIndexViewModel();

            IEnumerable <Movie>           movies = _database.Movies.ToList();
            IEnumerable <MovieGenreMovie> movieGenreMoviesFromDatabase = _database.MovieGenreMovies.ToList();
            List <MovieGenreMovie>        movieGenreMovies             = new List <MovieGenreMovie>();


            List <MovieGenre> genresFromDatabase = _database.MovieGenres.ToList();



            foreach (var movie in movies)
            {
                List <string> genres = new List <string>();
                movieGenreMovies = movieGenreMoviesFromDatabase.Where(a => a.MovieId == movie.Id).ToList();

                genres.Clear();
                if (movieGenreMovies != null)
                {
                    foreach (var genreId in movieGenreMovies)
                    {
                        MovieGenre genre = genresFromDatabase.FirstOrDefault(a => a.Id == genreId.MovieGenreId);
                        genres.Add(genre.Name);
                    }
                }

                var item = new MovieListItemViewModel
                {
                    Id          = movie.Id,
                    Title       = movie.Title,
                    ReleaseDate = movie.ReleaseDate,
                    PlayTime    = movie.PlayTime,
                    Genre       = genres,
                    Description = movie.Description,
                    Photo       = movie.Photo
                };

                model.MovieListItems.Add(item);
            }

            return(View(model));
        }
示例#26
0
        public async Task <ActionResult> Deleted()
        {
            _dataContext.SoftDeleteFilterIsActive = false;

            var model = new MovieIndexViewModel
            {
                IsShowingDeleted = true,
                Movies           = await _dataContext.Movies
                                   .OrderByDescending(movie => movie.AverageRating)
                                   .Where(movie => movie.IsDeleted)
                                   .Take(25)
                                   .Project().To <MovieIndexViewModel.Movie>()
                                   .ToListAsync()
            };

            _dataContext.SoftDeleteFilterIsActive = true;

            return(View("Index", model));
        }
        private void GetPopularMovies(MovieIndexViewModel indexViewModel)
        {
            indexViewModel.popularMovieModel = new List <MoviePopular>();

            TMDbClient client = new TMDbClient(ConfigurationManager.AppSettings["TMDbKey"]);
            SearchContainer <SearchMovie> movieApiResults = client.GetMoviePopularListAsync().Result;

            foreach (var newMovie in movieApiResults.Results)
            {
                MoviePopular popularMovie = new MoviePopular
                {
                    Id          = newMovie.Id,
                    Title       = newMovie.Title,
                    ReleaseDate = newMovie.ReleaseDate,
                    ImageUrl    = "http://image.tmdb.org/t/p/w185/" + newMovie.PosterPath
                };

                indexViewModel.popularMovieModel.Add(popularMovie);
            }
        }
        public async Task<IActionResult> Index(int id)
        {
            MovieDetailsServiceModel movieDetailsServiceModel = new MovieDetailsServiceModel();
            MovieIndexViewModel viewModel = new MovieIndexViewModel();

            bool isAjaxRequest = HttpContext.Request.IsAjaxRequest();

            if (isAjaxRequest)
            {
                movieDetailsServiceModel = await this.movieDbService.GetMovieDetailsAsync(id);

                if (movieDetailsServiceModel == null)
                {
                    return NotFound();
                }

                viewModel.MovieDetails = movieDetailsServiceModel;

                return PartialView("_Details", viewModel);
            }

            IEnumerable<MovieBaseServiceModel> allMovies
                = await this.movieDbService.GetAllMoviesAsync();

            if (allMovies != null && allMovies.Count() > 0)
            {
                int movieId = allMovies.FirstOrDefault().Id;
                movieDetailsServiceModel = await this.movieDbService.GetMovieDetailsAsync(movieId);

                viewModel.AllMovies = allMovies.AsNotNull();
                viewModel.MovieDetails = movieDetailsServiceModel;
            }

            viewModel.AllMovies = allMovies.AsNotNull();

            return View(viewModel);
        }
示例#29
0
        public ActionResult SubmitRating(int Rating, int MovieId)
        {
            string Message;

            if (Rating >= 0 && Rating <= 100)
            {
                Account account = HttpContext.Session.GetObject <Account>("User");
                Message = _ratinglogic.SubmitRating(Rating, MovieId, account);
            }
            else
            {
                Message = "Please insert a rating between 0 and 100";
            }

            MovieIndexViewModel viewModel = new MovieIndexViewModel
            {
                Account = HttpContext.Session.GetObject <Account>("User"),
                Movies  = _movielogic.GetMovies()
            };

            viewModel.Message = Message;

            return(View("Views/Movies/Index.cshtml", viewModel));
        }
示例#30
0
        public IActionResult Index()
        {
            // Gets a list of all films in order of Name, and then by Year and displays it in the view.

            // List<Film> films = _filmServices.GetAllCompleteFilms().ToList();
            List <Film> films = _context.Films
                                .Include(f => f.User)
                                .Where(f => (!f.IsPrivate && !f.User.IsPrivate) || User.IsInRole("Admin") || f.UserID == _userManager.GetUserId(User))
                                .ToList();

            // Filter out films that should not be visible to User based on privacy level
            //films = films.Where(f => (!f.IsPrivate && !f.User.IsPrivate)
            //    || f.UserID == _userManager.GetUserId(User)
            //    || User.IsInRole("Admin"))
            //    .ToList();

            MovieIndexViewModel movieIndexViewModel = new MovieIndexViewModel(films);

            List <ApplicationUser> users = _userServices.TakeUsers(15);

            movieIndexViewModel.Users = users;

            return(View(movieIndexViewModel));
        }
示例#31
0
 public ActionResult Index(MovieIndexViewModel vm)
 {
     return(View(vm));
 }
示例#32
0
        // GET: Movies
        public ActionResult Index()
        {
            MovieIndexViewModel vm = new MovieIndexViewModel();

            return View(vm);
        }