Пример #1
0
        public async Task <ActionResult> Filter()
        {
            var s = Encoding.Default.GetString(Request.Body.GetAllBytes());

            var tt = HttpUtility.UrlDecode(s);

            var inputDto = new MovieFilterInputDto();

            var kvs = tt?.Split("&");

            if (kvs != null)
            {
                foreach (var kv in kvs)
                {
                    var item = kv.Split("=");
                    switch (item[0])
                    {
                    case "tags":
                        inputDto.Tags = item[1].Split(",").ToList();
                        break;
                    }
                }
            }

            var movieList = await _movieService.MovieListAsync(inputDto);

            return(View("_Partial_MovieList", movieList));
        }
Пример #2
0
        public async Task <List <MovieListDto> > MovieListAsync(MovieFilterInputDto input = null)
        {
            var query = _movieRepository.GetAll();

            if (input == null)
            {
                var noFilterList = await query.OrderByDescending(c => c.Score).Take(20).ToListAsync();

                return(ObjectMapper.Map <List <MovieListDto> >(noFilterList));
            }

            if (input.Years.Any())
            {
                query = query.Where(c => input.Years.Contains(c.Year));
            }

            if (input.Tags.Any())
            {
                var movieId = _movieTagRepository.GetAll()
                              .Where(c => input.Tags.Contains(c.TagName)).Select(c => c.DoubanMovieId).Distinct();
                query = query.Where(c => movieId.Contains(c.DoubanId));
            }

            var filterList = await query.OrderByDescending(c => c.Score).PageBy(input).ToListAsync();

            return(ObjectMapper.Map <List <MovieListDto> >(filterList));
        }