using System.Collections.Generic; using System.Linq; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging; namespace NzbDrone.Core.MediaFiles { public interface IMediaFileRepository : IBasicRepository { EpisodeFile GetFileByPath(string path); List GetFilesBySeries(int seriesId); List GetFilesBySeason(int seriesId, int seasonNumber); bool Exists(string path); } public class MediaFileRepository : BasicRepository, IMediaFileRepository { public MediaFileRepository(IDatabase database, IMessageAggregator messageAggregator) : base(database, messageAggregator) { } public EpisodeFile GetFileByPath(string path) { return Query.SingleOrDefault(c => c.Path == path); } public List GetFilesBySeries(int seriesId) { return Query.Where(c => c.SeriesId == seriesId).ToList(); } public List GetFilesBySeason(int seriesId, int seasonNumber) { return Query.Where(c => c.SeriesId == seriesId) .AndWhere(c => c.SeasonNumber == seasonNumber) .ToList(); } public bool Exists(string path) { return Query.Any(c => c.Path == path); } } }