1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-16 16:04:08 +01:00
Radarr/NzbDrone.Web/Controllers/UpcomingController.cs

70 lines
3.1 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
2011-03-23 08:06:22 +01:00
using System.Web.Mvc;
using NzbDrone.Core;
2011-03-23 08:06:22 +01:00
using NzbDrone.Core.Providers;
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
public UpcomingController(UpcomingEpisodesProvider upcomingEpisodesProvider)
2011-03-23 08:06:22 +01:00
{
_upcomingEpisodesProvider = upcomingEpisodesProvider;
}
//
// GET: /Upcoming/
public ActionResult Index()
{
var upcomingEpisodes = GetUpcomingEpisodeModels(_upcomingEpisodesProvider.UpcomingEpisodes());
var upcoming = new UpcomingEpisodesModel
{
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()
};
return View(upcoming);
2011-03-23 08:06:22 +01:00
}
private List<UpcomingEpisodeModel> GetUpcomingEpisodeModels(List<Episode> episodes)
2011-03-23 08:06:22 +01:00
{
return episodes.Select(u => new UpcomingEpisodeModel
{
SeriesId = u.Series.SeriesId,
EpisodeId = u.EpisodeId,
SeriesTitle = u.Series.Title,
EpisodeNumbering = String.Format("{0}x{1:00}", u.SeasonNumber, u.EpisodeNumber),
Title = u.Title,
Overview = u.Overview,
AirDateTime = GetDateTime(u.AirDate.Value, u.Series.AirTimes),
AirDate = u.AirDate.Value.ToBestDateString(),
AirTime = String.IsNullOrEmpty(u.Series.AirTimes) ? "?" : Convert.ToDateTime(u.Series.AirTimes).ToShortTimeString(),
Status = u.Status.ToString()
}).OrderBy(e => e.AirDateTime).ToList();
2011-03-23 08:06:22 +01: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
}