2011-04-27 04:47:29 +02:00
|
|
|
|
using System;
|
2011-06-14 17:14:33 +02:00
|
|
|
|
using System.Collections.Generic;
|
2011-04-27 04:47:29 +02:00
|
|
|
|
using System.Linq;
|
2011-03-23 08:06:22 +01:00
|
|
|
|
using System.Web.Mvc;
|
2011-09-29 02:20:29 +02:00
|
|
|
|
using NzbDrone.Core;
|
2011-03-23 08:06:22 +01:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2012-02-07 02:22:17 +01:00
|
|
|
|
using NzbDrone.Core.Repository;
|
2011-03-23 08:06:22 +01:00
|
|
|
|
using NzbDrone.Web.Models;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class UpcomingController : Controller
|
|
|
|
|
{
|
2011-04-10 04:44:01 +02:00
|
|
|
|
private readonly UpcomingEpisodesProvider _upcomingEpisodesProvider;
|
2011-03-23 08:06:22 +01:00
|
|
|
|
|
2011-06-22 03:10:31 +02:00
|
|
|
|
public UpcomingController(UpcomingEpisodesProvider upcomingEpisodesProvider)
|
2011-03-23 08:06:22 +01:00
|
|
|
|
{
|
|
|
|
|
_upcomingEpisodesProvider = upcomingEpisodesProvider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// GET: /Upcoming/
|
|
|
|
|
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
2012-05-18 05:10:33 +02:00
|
|
|
|
var upcomingEpisodes = GetUpcomingEpisodeModels(_upcomingEpisodesProvider.UpcomingEpisodes());
|
2012-05-18 03:14:44 +02:00
|
|
|
|
|
|
|
|
|
|
2012-02-07 02:22:17 +01:00
|
|
|
|
var upcoming = new UpcomingEpisodesModel
|
|
|
|
|
{
|
2012-05-18 03:14:44 +02:00
|
|
|
|
Yesterday = upcomingEpisodes.Where(e => e.AirDateTime.Date == DateTime.Today.AddDays(-1)).ToList(),
|
|
|
|
|
Today = upcomingEpisodes.Where(e => e.AirDateTime.Date == DateTime.Today).ToList(),
|
|
|
|
|
Tomorrow = upcomingEpisodes.Where(e => e.AirDateTime.Date == DateTime.Today.AddDays(1)).ToList(),
|
|
|
|
|
TwoDays = upcomingEpisodes.Where(e => e.AirDateTime.Date == DateTime.Today.AddDays(2)).ToList(),
|
|
|
|
|
ThreeDays = upcomingEpisodes.Where(e => e.AirDateTime.Date == DateTime.Today.AddDays(3)).ToList(),
|
|
|
|
|
FourDays = upcomingEpisodes.Where(e => e.AirDateTime.Date == DateTime.Today.AddDays(4)).ToList(),
|
|
|
|
|
FiveDays = upcomingEpisodes.Where(e => e.AirDateTime.Date == DateTime.Today.AddDays(5)).ToList(),
|
|
|
|
|
SixDays = upcomingEpisodes.Where(e => e.AirDateTime.Date == DateTime.Today.AddDays(6)).ToList(),
|
|
|
|
|
Later = upcomingEpisodes.Where(e => e.AirDateTime.Date >= DateTime.Today.AddDays(7)).ToList()
|
2012-02-07 02:22:17 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return View(upcoming);
|
2011-03-23 08:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-07 02:22:17 +01:00
|
|
|
|
private List<UpcomingEpisodeModel> GetUpcomingEpisodeModels(List<Episode> episodes)
|
2011-03-23 08:06:22 +01:00
|
|
|
|
{
|
2012-02-07 02:22:17 +01:00
|
|
|
|
return episodes.Select(u => new UpcomingEpisodeModel
|
2011-06-14 17:14:33 +02:00
|
|
|
|
{
|
2011-06-20 05:08:09 +02:00
|
|
|
|
SeriesId = u.Series.SeriesId,
|
|
|
|
|
EpisodeId = u.EpisodeId,
|
2011-08-31 02:15:22 +02:00
|
|
|
|
SeriesTitle = u.Series.Title,
|
2012-02-09 23:34:59 +01:00
|
|
|
|
EpisodeNumbering = String.Format("{0}x{1:00}", u.SeasonNumber, u.EpisodeNumber),
|
2011-06-20 05:08:09 +02:00
|
|
|
|
Title = u.Title,
|
|
|
|
|
Overview = u.Overview,
|
2013-02-09 11:04:18 +01:00
|
|
|
|
AirDateTime = GetDateTime(u.AirDate.Value, u.Series.AirTime),
|
2011-09-29 02:20:29 +02:00
|
|
|
|
AirDate = u.AirDate.Value.ToBestDateString(),
|
2013-02-09 11:04:18 +01:00
|
|
|
|
AirTime = String.IsNullOrEmpty(u.Series.AirTime) ? "?" : Convert.ToDateTime(u.Series.AirTime).ToShortTimeString(),
|
2011-09-29 02:20:29 +02:00
|
|
|
|
Status = u.Status.ToString()
|
2012-02-07 02:22:17 +01:00
|
|
|
|
}).OrderBy(e => e.AirDateTime).ToList();
|
2011-03-23 08:06:22 +01:00
|
|
|
|
}
|
2011-10-11 03:11:22 +02:00
|
|
|
|
|
|
|
|
|
private DateTime GetDateTime(DateTime airDate, string airTime)
|
|
|
|
|
{
|
|
|
|
|
if (String.IsNullOrWhiteSpace(airTime))
|
|
|
|
|
return airDate;
|
|
|
|
|
|
|
|
|
|
return airDate.Add(Convert.ToDateTime(airTime).TimeOfDay);
|
|
|
|
|
}
|
2011-03-23 08:06:22 +01:00
|
|
|
|
}
|
2011-04-10 04:44:01 +02:00
|
|
|
|
}
|