You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sonarr/NzbDrone.Core/Tv/EpisodeRepository.cs

87 lines
6.8 KiB

using System;
using System.Collections.Generic;
12 years ago
using System.Data;
using System.Linq;
using NzbDrone.Core.Datastore;
12 years ago
using ServiceStack.OrmLite;
namespace NzbDrone.Core.Tv
{
public interface IEpisodeRepository : IBasicRepository<Episode>
{
Episode Get(int seriesId, int season, int episodeNumber);
Episode Get(int seriesId, DateTime date);
List<Episode> GetEpisodes(int seriesId);
List<Episode> GetEpisodes(int seriesId, int seasonNumber);
List<Episode> GetEpisodeByFileId(int fileId);
List<Episode> EpisodesWithoutFiles(bool includeSpecials);
Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber);
List<Episode> EpisodesWithFiles();
List<Episode> EpisodesBetweenDates(DateTime startDate, DateTime endDate);
void SetIgnoreFlat(Episode episode, bool ignoreFlag);
}
public class EpisodeRepository : BasicRepository<Episode>, IEpisodeRepository
{
12 years ago
public EpisodeRepository(IDbConnection database)
: base(database)
{
}
public Episode Get(int seriesId, int season, int episodeNumber)
{
12 years ago
return Single(s => s.SeriesId == seriesId && s.SeasonNumber == season && s.EpisodeNumber == episodeNumber);
}
public Episode Get(int seriesId, DateTime date)
{
12 years ago
return Single(s => s.SeriesId == seriesId && s.AirDate.HasValue && s.AirDate.Value.Date == date.Date);
}
public List<Episode> GetEpisodes(int seriesId)
{
12 years ago
return Where(s => s.SeriesId == seriesId).ToList();
}
public List<Episode> GetEpisodes(int seriesId, int seasonNumber)
{
12 years ago
return Where(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber).ToList();
}
public List<Episode> GetEpisodeByFileId(int fileId)
{
12 years ago
return Where(s => s.EpisodeFile != null && s.EpisodeFile.Id == fileId).ToList();
}
public List<Episode> EpisodesWithoutFiles(bool includeSpecials)
{
if (!includeSpecials)
{
12 years ago
return Where(s => s.EpisodeFile == null && s.SeasonNumber != 0).ToList();
}
12 years ago
return Where(s => s.EpisodeFile == null).ToList();
}
public Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber)
{
12 years ago
return Single(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber && s.SceneEpisodeNumber == episodeNumber);
}
public List<Episode> EpisodesWithFiles()
{
12 years ago
return Where(s => s.EpisodeFile != null).ToList();
}
public List<Episode> EpisodesBetweenDates(DateTime startDate, DateTime endDate)
{
12 years ago
return Where(s => s.AirDate >= startDate && s.AirDate <= endDate).ToList();
}
public void SetIgnoreFlat(Episode episode, bool ignoreFlag)
{
episode.Ignored = ignoreFlag;
UpdateFields(episode, p => p.Ignored);
}
}
}