1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-09 12:32:31 +01:00
Radarr/NzbDrone.Core/Tv/EpisodeRepository.cs

100 lines
7.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2013-03-24 05:16:00 +01:00
using System.Data;
using System.Linq;
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Model;
2013-03-25 04:51:32 +01:00
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);
2013-03-01 08:03:41 +01:00
void SetIgnoreFlat(Episode episode, bool ignoreFlag);
void SetPostDownloadStatus(int episodeId, PostDownloadStatusType status);
void SetFileId(int episodeId, int fileId);
}
public class EpisodeRepository : BasicRepository<Episode>, IEpisodeRepository
{
2013-03-25 04:51:32 +01:00
public EpisodeRepository(IDatabase database)
2013-03-24 05:16:00 +01:00
: base(database)
{
}
public Episode Get(int seriesId, int season, int episodeNumber)
{
2013-03-27 04:44:52 +01:00
return Query.Single(s => s.SeriesId == seriesId && s.SeasonNumber == season && s.EpisodeNumber == episodeNumber);
}
public Episode Get(int seriesId, DateTime date)
{
2013-03-27 04:44:52 +01:00
return Query.Single(s => s.SeriesId == seriesId && s.AirDate.HasValue && s.AirDate.Value.Date == date.Date);
}
public List<Episode> GetEpisodes(int seriesId)
{
2013-03-27 04:44:52 +01:00
return Query.Where(s => s.SeriesId == seriesId).ToList();
}
public List<Episode> GetEpisodes(int seriesId, int seasonNumber)
{
2013-03-27 04:44:52 +01:00
return Query.Where(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber).ToList();
}
public List<Episode> GetEpisodeByFileId(int fileId)
{
2013-03-27 04:44:52 +01:00
return Query.Where(s => s.EpisodeFile != null && s.EpisodeFile.Id == fileId).ToList();
}
public List<Episode> EpisodesWithoutFiles(bool includeSpecials)
{
if (!includeSpecials)
{
2013-03-27 04:44:52 +01:00
return Query.Where(s => s.EpisodeFile == null && s.SeasonNumber != 0).ToList();
}
2013-03-27 04:44:52 +01:00
return Query.Where(s => s.EpisodeFile == null).ToList();
}
public Episode GetEpisodeBySceneNumbering(int seriesId, int seasonNumber, int episodeNumber)
{
2013-03-27 04:44:52 +01:00
return Query.Single(s => s.SeriesId == seriesId && s.SeasonNumber == seasonNumber && s.SceneEpisodeNumber == episodeNumber);
}
public List<Episode> EpisodesWithFiles()
{
2013-03-27 04:44:52 +01:00
return Query.Where(s => s.EpisodeFile != null).ToList();
}
public List<Episode> EpisodesBetweenDates(DateTime startDate, DateTime endDate)
{
2013-03-27 04:44:52 +01:00
return Query.Where(s => s.AirDate >= startDate && s.AirDate <= endDate).ToList();
}
2013-03-01 08:03:41 +01:00
public void SetIgnoreFlat(Episode episode, bool ignoreFlag)
{
episode.Ignored = ignoreFlag;
SetFields(episode, p => p.Ignored);
2013-03-01 08:03:41 +01:00
}
public void SetPostDownloadStatus(int episodeId, PostDownloadStatusType status)
{
SetFields(new Episode { Id = episodeId, PostDownloadStatus = status }, episode => episode.PostDownloadStatus);
}
public void SetFileId(int episodeId, int fileId)
{
SetFields(new Episode { Id = episodeId, EpisodeFileId = fileId }, episode => episode.EpisodeFileId);
}
}
}