Example #1
0
        public void OnGet(MovieIndexVM movieIndex)
        {
            int? favouriteId = HttpContext.Session.GetInt32("favouriteId");
            bool isUser      = _signInManager.IsSignedIn(User);

            if (isUser && favouriteId == null)
            {
                string userId = _userManager.FindByNameAsync(User.Identity.Name).Result.Id;
                Favourite = _db.Favourites
                            .Include(f => f.FavouriteMovies)
                            .ThenInclude(fm => fm.Movie)
                            .Where(f => f.UserId == userId)
                            .FirstOrDefault();
                if (Favourite != null)
                {
                    HttpContext.Session.SetInt32("favouriteId", Favourite.Id);
                }
            }
            else if (isUser && favouriteId != null)
            {
                string userId = _userManager.FindByNameAsync(User.Identity.Name).Result.Id;
                Favourite = _db.Favourites
                            .Include(f => f.FavouriteMovies)
                            .ThenInclude(fm => fm.Movie)
                            .Where(f => f.UserId == userId)
                            .FirstOrDefault();
                if (Favourite != null)
                {
                    HttpContext.Session.SetInt32("favouriteId", Favourite.Id);
                }
            }
            MovieIndex = _movieVMService.GetMoviesVM(movieIndex.CategoriesFilterApplied);
        }
        public ActionResult Index()
        {
            MovieIndexVM model = new MovieIndexVM();

            model.Movies = MovieManager.GetAll();
            return(View(model));
        }
Example #3
0
        public ActionResult Index(int id = 0)
        {
            MovieIndexVM vm = new MovieIndexVM
            {
                SelectedGenre = id == 0 ? null : db.Genres.First(x => x.GenreId == id),
                Genres        = db.Genres.Include(s => s.Movies).ToList()
            };

            return(View(vm));
        }
Example #4
0
        public MovieIndexVM GetMoviesVM(int pageIndex, int itemsPerPage, int?categoryId)
        {
            IQueryable <Movie> movies = _movieRepo.GetAll();


            if (categoryId != null)
            {
                movies = movies.Where(m => m.CategoryId == categoryId);
            }

            int totalItems = movies.Count();

            movies = movies.Skip(pageIndex * itemsPerPage).Take(itemsPerPage);

            var vm = new MovieIndexVM()
            {
                Movies = movies.Select(m => new MovieVM
                {
                    Id          = m.Id,
                    Title       = m.Title,
                    Overview    = m.Overview,
                    ReleaseDate = m.ReleaseDate.ToString("MMMM dd, yyyy"),
                    PosterPath  = "https://image.tmdb.org/t/p/w500" + m.PosterPath
                }).ToList(),
                Categories     = GetCategories().ToList(),
                PaginationInfo = new PaginationInfoVM()
                {
                    PageIndex    = pageIndex,
                    ItemsPerPage = movies.Count(),
                    TotalItems   = totalItems,
                    TotalPages   = int.Parse(Math.Ceiling((decimal)totalItems / itemsPerPage).ToString())
                }
            };

            vm.PaginationInfo.Previuos = vm.PaginationInfo.PageIndex == 0 ? "is-disabled" : "";
            vm.PaginationInfo.Next     = vm.PaginationInfo.PageIndex == vm.PaginationInfo.TotalPages - 1? "is-disabled" : "";
            return(vm);
        }
        public MovieIndexVM GetMoviesVM(int?categoryId)
        {
            IQueryable <Movie> movies = _movieRepo.GetAll();

            if (categoryId != null)
            {
                movies = movies.Where(m => m.CategoryId == categoryId);
            }

            var vm = new MovieIndexVM()
            {
                Movies = movies.Select(m => new MovieVM
                {
                    Id          = m.Id,
                    Title       = m.Title,
                    Overview    = m.Overview,
                    ReleaseDate = m.ReleaseDate.ToString("MMMM dd, yyyy"),
                    PosterPath  = "https://image.tmdb.org/t/p/w500" + m.PosterPath
                }).ToList(),
                Categories = GetCategories().ToList()
            };

            return(vm);
        }
Example #6
0
 public IActionResult Index(MovieIndexVM model)
 {
     return(View());
 }