public Task <IEnumerable <FilmProductionRating> > GetAll(int page, FilmProductionType type, string search)
        {
            int filmProductionsPerPage = 100;

            return(_filmProductionRepository.GetAll(page * filmProductionsPerPage - 100, filmProductionsPerPage, type, search));
        }
Ejemplo n.º 2
0
 public async Task <ActionResult <IEnumerable <FilmProductionRating> > > GetAll(int page = 1, FilmProductionType type = FilmProductionType.all, string search = "")
 {
     return(Ok(await _filmProductionService.GetAll(page, type, search)));
 }
Ejemplo n.º 3
0
        public async Task <IEnumerable <FilmProductionRating> > GetAll(int from, int to, FilmProductionType type, string search)
        {
            int?lastId = (await _dbContext.FilmProductions
                          .Include(f => f.Reviews)
                          .Where(f => type == FilmProductionType.all ? true : (f.IsSeries == (type == FilmProductionType.serials)))
                          .Where(f => f.Title.Contains(search))
                          .ToAsyncEnumerable()
                          .OrderByDescending(f => Average(f))
                          .LastOrDefault())?.Id;
            List <FilmProduction> d = await _dbContext.FilmProductions
                                      .Include(f => f.Reviews)
                                      .Include(f => f.Episodes)
                                      .Where(f => type == FilmProductionType.all ? true : (f.IsSeries == (type == FilmProductionType.serials)))
                                      .Where(f => f.Title.Contains(search))
                                      .Skip(from).Take(to).ToListAsync();

            return(d.OrderByDescending(f => Average(f))
                   .Select(f => new FilmProductionRating
            {
                FilmProductionId = f.Id,
                IsSeries = f.IsSeries,
                Seasons = f.Episodes.Any() ? (int?)f.Episodes.OrderByDescending(i => i.Season).Select(s => s.Season).FirstOrDefault() : null,
                Genre = f.Genre,
                Poster = f.Poster,
                Rating = Average(f),
                Plot = f.Plot,
                Released = f.Released,
                Title = f.Title,
                Votes = f.Reviews.Count(),
                Last = lastId == null ? true : f.Id == lastId
            }));
        }