2011-03-23 08:06:22 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2011-06-14 03:23:04 +02:00
|
|
|
|
using Ninject;
|
2011-03-23 08:06:22 +01:00
|
|
|
|
using NzbDrone.Core.Model;
|
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-06-18 01:01:09 +02:00
|
|
|
|
using PetaPoco;
|
2011-03-23 08:06:22 +01:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Providers
|
|
|
|
|
{
|
2011-04-08 17:18:01 +02:00
|
|
|
|
public class UpcomingEpisodesProvider
|
2011-03-23 08:06:22 +01:00
|
|
|
|
{
|
2011-06-18 01:01:09 +02:00
|
|
|
|
private readonly IDatabase _database;
|
2011-03-23 08:06:22 +01:00
|
|
|
|
|
2011-06-14 03:23:04 +02:00
|
|
|
|
[Inject]
|
2011-06-18 01:01:09 +02:00
|
|
|
|
public UpcomingEpisodesProvider(IDatabase database)
|
2011-03-23 08:06:22 +01:00
|
|
|
|
{
|
2011-06-18 01:01:09 +02:00
|
|
|
|
_database = database;
|
2011-03-23 08:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-08 17:18:01 +02:00
|
|
|
|
public virtual UpcomingEpisodesModel Upcoming()
|
2011-03-23 08:06:22 +01:00
|
|
|
|
{
|
2011-06-20 05:08:09 +02:00
|
|
|
|
var allEps = _database.Fetch<Episode, Series>(@"SELECT * FROM Episodes
|
|
|
|
|
INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId
|
2011-10-04 01:53:21 +02:00
|
|
|
|
WHERE Ignored = 0 AND AirDate BETWEEN @0 AND @1",
|
2011-06-20 05:08:09 +02:00
|
|
|
|
DateTime.Today.AddDays(-1), DateTime.Today.AddDays(8));
|
2011-03-23 08:06:22 +01:00
|
|
|
|
|
|
|
|
|
var yesterday = allEps.Where(e => e.AirDate == DateTime.Today.AddDays(-1)).ToList();
|
|
|
|
|
var today = allEps.Where(e => e.AirDate == DateTime.Today).ToList();
|
|
|
|
|
var week = allEps.Where(e => e.AirDate > DateTime.Today).ToList();
|
|
|
|
|
|
2011-06-14 03:23:04 +02:00
|
|
|
|
return new UpcomingEpisodesModel { Yesterday = yesterday, Today = today, Week = week };
|
2011-03-23 08:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-08 17:18:01 +02:00
|
|
|
|
public virtual List<Episode> Yesterday()
|
2011-03-23 08:06:22 +01:00
|
|
|
|
{
|
2011-06-20 05:08:09 +02:00
|
|
|
|
return _database.Fetch<Episode, Series>(@"SELECT * FROM Episodes
|
|
|
|
|
INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId
|
2011-10-04 01:53:21 +02:00
|
|
|
|
WHERE Ignored = 0 AND AirDate = @0", DateTime.Today.AddDays(-1));
|
2011-03-23 08:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-08 17:18:01 +02:00
|
|
|
|
public virtual List<Episode> Today()
|
2011-03-23 08:06:22 +01:00
|
|
|
|
{
|
2011-06-20 05:08:09 +02:00
|
|
|
|
return _database.Fetch<Episode, Series>(@"SELECT * FROM Episodes
|
|
|
|
|
INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId
|
2011-10-04 01:53:21 +02:00
|
|
|
|
WHERE Ignored = 0 AND AirDate = @0", DateTime.Today);
|
2011-03-23 08:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-28 01:51:38 +02:00
|
|
|
|
public virtual List<Episode> Tomorrow()
|
|
|
|
|
{
|
2011-06-20 05:08:09 +02:00
|
|
|
|
return _database.Fetch<Episode, Series>(@"SELECT * FROM Episodes
|
|
|
|
|
INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId
|
2011-10-04 01:53:21 +02:00
|
|
|
|
WHERE Ignored = 0 AND AirDate = @0", DateTime.Today.AddDays(1));
|
2011-04-28 01:51:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-08 17:18:01 +02:00
|
|
|
|
public virtual List<Episode> Week()
|
2011-03-23 08:06:22 +01:00
|
|
|
|
{
|
2011-06-20 05:08:09 +02:00
|
|
|
|
return _database.Fetch<Episode, Series>(@"SELECT * FROM Episodes
|
|
|
|
|
INNER JOIN Series ON Episodes.SeriesId = Series.SeriesId
|
2011-10-04 01:53:21 +02:00
|
|
|
|
WHERE Ignored = 0 AND AirDate BETWEEN @0 AND @1", DateTime.Today.AddDays(2), DateTime.Today.AddDays(8));
|
2011-03-23 08:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-10 04:44:01 +02:00
|
|
|
|
}
|