1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-10 04:52:42 +01:00
Radarr/NzbDrone.Core/Tv/SeriesRepository.cs

76 lines
2.6 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
2013-03-25 04:51:32 +01:00
using System.Linq;
2013-02-19 07:56:02 +01:00
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.Tv
{
2013-03-24 05:16:00 +01:00
public interface ISeriesRepository : IBasicRepository<Series>
2013-02-19 07:56:02 +01:00
{
bool SeriesPathExists(string path);
List<Series> Search(string title);
Series FindByTitle(string cleanTitle);
2013-03-02 19:25:39 +01:00
Series FindByTvdbId(int tvdbId);
void SetSeriesType(int seriesId, SeriesTypes seriesTypes);
2013-03-31 22:25:39 +02:00
void SetTvRageId(int seriesId, int tvRageId);
2013-04-20 22:09:12 +02:00
List<SeriesStatistics> SeriesStatistics();
2013-02-19 07:56:02 +01:00
}
2013-03-24 05:16:00 +01:00
public class SeriesRepository : BasicRepository<Series>, ISeriesRepository
2013-02-19 07:56:02 +01:00
{
2013-04-20 22:09:12 +02:00
private readonly IDatabase _database;
2013-03-25 04:51:32 +01:00
public SeriesRepository(IDatabase database)
2013-03-24 01:08:23 +01:00
: base(database)
2013-02-19 07:56:02 +01:00
{
2013-04-20 22:09:12 +02:00
_database = database;
2013-02-19 07:56:02 +01:00
}
public bool SeriesPathExists(string path)
{
2013-03-27 04:44:52 +01:00
return Query.Any(c => c.Path == path);
2013-02-19 07:56:02 +01:00
}
public List<Series> Search(string title)
{
2013-03-27 04:44:52 +01:00
return Query.Where(s => s.Title.Contains(title));
2013-02-19 07:56:02 +01:00
}
public Series FindByTitle(string cleanTitle)
2013-02-19 07:56:02 +01:00
{
return Query.SingleOrDefault(s => s.CleanTitle.Equals(cleanTitle, StringComparison.InvariantCultureIgnoreCase));
2013-02-19 07:56:02 +01:00
}
2013-03-02 19:25:39 +01:00
public Series FindByTvdbId(int tvdbId)
{
return Query.SingleOrDefault(s => s.TvdbId.Equals(tvdbId));
2013-03-02 19:25:39 +01:00
}
2013-03-24 01:08:23 +01:00
public void SetSeriesType(int seriesId, SeriesTypes seriesType)
2013-03-02 19:25:39 +01:00
{
SetFields(new Series { Id = seriesId, SeriesType = seriesType }, s => s.SeriesType);
2013-03-02 19:25:39 +01:00
}
2013-03-31 22:25:39 +02:00
public void SetTvRageId(int seriesId, int tvRageId)
{
SetFields(new Series { Id = seriesId, TvRageId = tvRageId }, s => s.TvRageId);
}
2013-04-20 22:09:12 +02:00
public List<SeriesStatistics> SeriesStatistics()
{
_database.DataMapper.AddParameter("currentDate", DateTime.UtcNow);
var queryText = @"SELECT
SeriesId,
SUM(CASE WHEN Airdate <= @currentDate THEN 1 ELSE 0 END) AS EpisodeCount,
SUM(CASE WHEN EpisodeFileId > 0 AND AirDate <= @currentDate THEN 1 ELSE 0 END) as EpisodeFileCount,
MAX(SeasonNumber) as NumberOfSeasons,
MIN(CASE WHEN AirDate < @currentDate THEN NULL ELSE AirDate END) as NextAiring
FROM Episodes
WHERE Ignored = 0
GROUP BY SeriesId";
return _database.DataMapper.Query<SeriesStatistics>(queryText);
}
2013-02-19 07:56:02 +01:00
}
}