Exemple #1
0
        // GET: /rentings
        public async Task <ActionResult> Index(int?page)
        {
            try
            {
                // rules of paging
                var PageSize   = 5;
                var PageNumber = (page ?? 1);

                var allRentings = await _rentingService.GetAllActiveRentings();

                var rentingViewModels = _mapper.Map <List <RentingViewModel> >(allRentings);

                foreach (RentingViewModel renting in rentingViewModels)
                {
                    renting.Poster = await _OMDbAPI.GetMovieArtworkByTitle(renting.Copy.Movie.Title);
                }

                return(View(rentingViewModels.ToPagedList(PageNumber, PageSize)));
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
                return(View("Error"));
            }
        }
Exemple #2
0
        // GET: /customers/rentings?customer
        public async Task <ActionResult> Rentings(string customer, int?page)
        {
            try
            {
                if (!String.IsNullOrEmpty(customer))
                {
                    // rules of paging
                    var PageSize   = 5;
                    var PageNumber = (page ?? 1);

                    ViewBag.Customer = customer;

                    var rentings = await _rentingService.GetAllUserRentings(customer);

                    var rentingViewModels = _mapper.Map <List <RentingViewModel> >(rentings);

                    foreach (RentingViewModel renting in rentingViewModels)
                    {
                        renting.Poster = await _OMDbAPI.GetMovieArtworkByTitle(renting.Copy.Movie.Title);
                    }

                    return(View(rentingViewModels.ToPagedList(PageNumber, PageSize)));
                }
                else
                {
                    return(View("Error"));
                }
            }
            catch (Exception e)
            {
                _logger.Writer.Fatal(e, "/customers/rentings?customer={Customer} View could not be loaded.", customer);
                return(View("Error"));
            }
        }
Exemple #3
0
        private async Task <PaginationModel <MovieViewModel> > GetPaginatedMovies(PaginationDto pagination, IQueryable <Movie> movies)
        {
            var moviesCount = await movies.CountAsync();

            var toSkip = (pagination.CurrentPage - 1) * pagination.PageSize;

            movies = movies
                     .Skip(toSkip)
                     .Take(pagination.PageSize);

            var movieViewModels = _mapper.Map <List <MovieViewModel> >(movies);

            foreach (var movie in movieViewModels)
            {
                movie.Genres = Movie.ConvertToGenres(movie.MovieGenres);
                movie.Poster = await _OMDbAPI.GetMovieArtworkByTitle(movie.Title);
            }

            return(new PaginationModel <MovieViewModel>(movieViewModels, pagination.CurrentPage, pagination.PageSize, moviesCount));
        }