Ejemplo n.º 1
0
        public Pagination <MovieWithRatingViewModel> GetMovies(MovieFilterViewModel viewModel, int pageNumber, int pageSize)
        {
            Expression <Func <Movie, bool> > predicate = ExpressionExtension.Query <Movie>();

            if (viewModel == null)
            {
                if (viewModel.Genre.HasValue)
                {
                    predicate = predicate.And(it => it.Genre == viewModel.Genre);
                }

                if (!string.IsNullOrWhiteSpace(viewModel.Title))
                {
                    predicate = predicate.And(it => it.Title.ToLower().Equals(viewModel.Title.ToLower()));
                }

                if (viewModel.CastIds != null && viewModel.CastIds.Any())
                {
                    predicate = predicate.And(it => it.CastOfMovies.Any(x => viewModel.CastIds.Contains(x.Cast.Id)));
                }
            }

            var moviesPagination = _movieRepository.GetMoviesWithPagination(predicate, pageNumber, pageSize);
            var map = _mapper.Map <Pagination <MovieWithRatingViewModel> >(moviesPagination);

            return(map);
        }
Ejemplo n.º 2
0
        public IActionResult GetMovieByFilters([FromBody] MovieFilterViewModel viewModel, int pageNumber = 1, int pageSize = 10)
        {
            var movies = _movieAppService.GetMovies(viewModel, pageNumber, pageSize);

            return(GetResponse(movies));
        }