using System.Collections.Generic; using System.Linq; using NLog; using NzbDrone.Core.Datastore; using NzbDrone.Core.Profiles; using NzbDrone.Core.Qualities; namespace NzbDrone.Core.Movies { public interface IMovieCutoffService { PagingSpec MoviesWhereCutoffUnmet(PagingSpec pagingSpec); } public class MovieCutoffService : IMovieCutoffService { private readonly IMovieRepository _movieRepository; private readonly IProfileService _profileService; public MovieCutoffService(IMovieRepository movieRepository, IProfileService profileService, Logger logger) { _movieRepository = movieRepository; _profileService = profileService; } public PagingSpec MoviesWhereCutoffUnmet(PagingSpec pagingSpec) { var qualitiesBelowCutoff = new List(); var profiles = _profileService.All(); //Get all items less than the cutoff foreach (var profile in profiles) { var cutoffIndex = profile.GetIndex(profile.Cutoff); var belowCutoff = profile.Items.Take(cutoffIndex.Index).ToList(); if (belowCutoff.Any()) { qualitiesBelowCutoff.Add(new QualitiesBelowCutoff(profile.Id, belowCutoff.SelectMany(i => i.GetQualities().Select(q => q.Id)))); } } return _movieRepository.MoviesWhereCutoffUnmet(pagingSpec, qualitiesBelowCutoff); } } }