2013-02-19 07:56:02 +01:00
|
|
|
|
using System.Collections.Generic;
|
2013-03-24 01:08:23 +01:00
|
|
|
|
using System.Data;
|
2013-02-19 07:56:02 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using NzbDrone.Core.Datastore;
|
2013-03-24 01:08:23 +01:00
|
|
|
|
using ServiceStack.OrmLite;
|
2013-02-19 07:56:02 +01:00
|
|
|
|
|
|
|
|
|
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);
|
2013-02-20 03:05:15 +01:00
|
|
|
|
Series GetByTitle(string cleanTitle);
|
2013-03-02 19:25:39 +01:00
|
|
|
|
Series FindByTvdbId(int tvdbId);
|
2013-03-04 06:53:02 +01:00
|
|
|
|
void SetSeriesType(int seriesId, SeriesTypes seriesTypes);
|
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-03-24 01:08:23 +01:00
|
|
|
|
public SeriesRepository(IDbConnection database)
|
|
|
|
|
: base(database)
|
2013-02-19 07:56:02 +01:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool SeriesPathExists(string path)
|
|
|
|
|
{
|
2013-03-24 01:08:23 +01:00
|
|
|
|
return Database.Exists<Series>("WHERE Path = {0}", path);
|
2013-02-19 07:56:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Series> Search(string title)
|
|
|
|
|
{
|
2013-03-24 01:08:23 +01:00
|
|
|
|
return Database.Select<Series>(s => s.Title.Contains(title));
|
2013-02-19 07:56:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 03:05:15 +01:00
|
|
|
|
public Series GetByTitle(string cleanTitle)
|
2013-02-19 07:56:02 +01:00
|
|
|
|
{
|
2013-03-24 01:08:23 +01:00
|
|
|
|
return Database.Select<Series>(s => s.CleanTitle.Equals(cleanTitle)).SingleOrDefault();
|
2013-02-19 07:56:02 +01:00
|
|
|
|
}
|
2013-03-02 19:25:39 +01:00
|
|
|
|
|
|
|
|
|
public Series FindByTvdbId(int tvdbId)
|
|
|
|
|
{
|
2013-03-24 01:08:23 +01:00
|
|
|
|
return Database.Select<Series>(s => s.TvDbId.Equals(tvdbId)).SingleOrDefault();
|
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
|
|
|
|
{
|
2013-03-24 01:08:23 +01:00
|
|
|
|
Database.UpdateOnly(new Series { SeriesType = seriesType }, s => s.SeriesType, s => s.Id == seriesId);
|
2013-03-02 19:25:39 +01:00
|
|
|
|
}
|
2013-02-19 07:56:02 +01:00
|
|
|
|
}
|
|
|
|
|
}
|