2013-01-19 05:14:12 +00:00
|
|
|
|
using System.Collections.Generic;
|
2012-02-21 06:50:38 +00:00
|
|
|
|
using System.Linq;
|
2013-02-19 06:01:03 +00:00
|
|
|
|
using NzbDrone.Core.Tv;
|
2012-02-21 06:50:38 +00:00
|
|
|
|
using NzbDrone.Core.Repository;
|
|
|
|
|
|
2013-02-18 07:59:43 +00:00
|
|
|
|
// ReSharper disable CheckNamespace
|
2013-02-16 04:03:54 +00:00
|
|
|
|
namespace PetaPoco
|
2012-02-21 06:50:38 +00:00
|
|
|
|
{
|
|
|
|
|
public class EpisodeSeasonRelator
|
|
|
|
|
{
|
|
|
|
|
public Season _current;
|
2012-02-25 00:53:01 +00:00
|
|
|
|
public Season MapIt(Season season, Episode episode, EpisodeFile episodeFile)
|
2012-02-21 06:50:38 +00:00
|
|
|
|
{
|
|
|
|
|
// Terminating call. Since we can return null from this function
|
|
|
|
|
// we need to be ready for PetaPoco to callback later with null
|
|
|
|
|
// parameters
|
|
|
|
|
if (season == null)
|
|
|
|
|
return _current;
|
|
|
|
|
|
2012-02-25 00:53:01 +00:00
|
|
|
|
//Todo: Find a Query that doesn't require this check
|
|
|
|
|
//Map EpisodeFile to Episode (Map to null if 0, because PetaPoco is returning a POCO when it should be null)
|
|
|
|
|
episode.EpisodeFile = (episode.EpisodeFileId == 0 ? null : episodeFile);
|
|
|
|
|
|
2012-02-21 06:50:38 +00:00
|
|
|
|
// Is this the same season as the current one we're processing
|
|
|
|
|
if (_current != null && _current.SeasonId == season.SeasonId)
|
|
|
|
|
{
|
|
|
|
|
// Yes, just add this post to the current author's collection of posts
|
|
|
|
|
_current.Episodes.Add(episode);
|
|
|
|
|
|
|
|
|
|
// Return null to indicate we're not done with this author yet
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This is season different author to the current one, or this is the
|
|
|
|
|
// first time through and we don't have an season yet
|
|
|
|
|
|
|
|
|
|
// Save the current author
|
|
|
|
|
var prev = _current;
|
|
|
|
|
|
|
|
|
|
// Setup the new current season
|
|
|
|
|
_current = season;
|
|
|
|
|
_current.Episodes = new List<Episode>();
|
|
|
|
|
_current.Episodes.Add(episode);
|
|
|
|
|
|
|
|
|
|
// Return the now populated previous season (or null if first time through)
|
|
|
|
|
return prev;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|