/// <summary>Adds a <see cref="ITraktShow" />, which will be added to the watchlist post.</summary> /// <param name="show">The Trakt show, which will be added.</param> /// <param name="seasons"> /// An array of season numbers for seasons in the given show. /// All seasons numbers will be added to the ratings. /// </param> /// <returns>The current <see cref="TraktSyncWatchlistPostBuilder" /> instance.</returns> /// <exception cref="ArgumentNullException"> /// Thrown, if the given show is null. /// Thrown, if the given show ids are null. /// Thrown, if the given seasons array is null. /// </exception> /// <exception cref="ArgumentException"> /// Thrown, if the given show has no valid ids set. /// Thrown, if the given show has an year set, which has more or less than four digits. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// Thrown, if at least one of the given season numbers is below zero. /// </exception> public TraktSyncWatchlistPostBuilder AddShow(ITraktShow show, int[] seasons) { ValidateShow(show); EnsureShowsListExists(); if (seasons == null) { throw new ArgumentNullException(nameof(seasons)); } var showSeasons = new List <ITraktSyncWatchlistPostShowSeason>(); for (int i = 0; i < seasons.Length; i++) { if (seasons[i] < 0) { throw new ArgumentOutOfRangeException("at least one season number not valid"); } showSeasons.Add(new TraktSyncWatchlistPostShowSeason { Number = seasons[i] }); } var existingShow = _watchlistPost.Shows.FirstOrDefault(s => s.Ids == show.Ids); if (existingShow != null) { existingShow.Seasons = showSeasons; } else { var watchlistShow = new TraktSyncWatchlistPostShow { Ids = show.Ids, Title = show.Title, Year = show.Year, Seasons = showSeasons }; (_watchlistPost.Shows as List <ITraktSyncWatchlistPostShow>)?.Add(watchlistShow); } return(this); }
/// <summary>Adds a <see cref="ITraktShow" />, which will be added to the watchlist post.</summary> /// <param name="show">The Trakt show, which will be added.</param> /// <param name="seasons"> /// An <see cref="PostSeasons" /> instance, containing season and episode numbers.<para /> /// If it contains episode numbers, only the episodes with the given episode numbers will be added to the watchlist. /// </param> /// <returns>The current <see cref="TraktSyncWatchlistPostBuilder" /> instance.</returns> /// <exception cref="ArgumentNullException"> /// Thrown, if the given show is null. /// Thrown, if the given show ids are null. /// </exception> /// <exception cref="ArgumentException"> /// Thrown, if the given show has no valid ids set. /// Thrown, if the given show has an year set, which has more or less than four digits. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// Thrown, if at least one of the given season numbers in <paramref name="seasons" /> is below zero. /// Thrown, if at least one of the given episode numbers in <paramref name="seasons" /> is below zero. /// </exception> public TraktSyncWatchlistPostBuilder AddShow(ITraktShow show, PostSeasons seasons) { ValidateShow(show); EnsureShowsListExists(); if (_watchlistPost.Shows == null) { _watchlistPost.Shows = new List <ITraktSyncWatchlistPostShow>(); } List <ITraktSyncWatchlistPostShowSeason> showSeasons = null; if (seasons.Any()) { showSeasons = new List <ITraktSyncWatchlistPostShowSeason>(); foreach (PostSeason season in seasons) { if (season.Number < 0) { throw new ArgumentOutOfRangeException("at least one season number not valid", nameof(season)); } var showSingleSeason = new TraktSyncWatchlistPostShowSeason { Number = season.Number }; if (season.Episodes?.Count() > 0) { var showEpisodes = new List <TraktSyncWatchlistPostShowEpisode>(); foreach (PostEpisode episode in season.Episodes) { if (episode.Number < 0) { throw new ArgumentOutOfRangeException("at least one episode number not valid", nameof(seasons)); } showEpisodes.Add(new TraktSyncWatchlistPostShowEpisode { Number = episode.Number }); } showSingleSeason.Episodes = showEpisodes; } showSeasons.Add(showSingleSeason); } } ITraktSyncWatchlistPostShow existingShow = _watchlistPost.Shows.FirstOrDefault(s => s.Ids == show.Ids); if (existingShow != null) { existingShow.Seasons = showSeasons; } else { var watchlistShow = new TraktSyncWatchlistPostShow { Ids = show.Ids, Title = show.Title, Year = show.Year, Seasons = showSeasons }; (_watchlistPost.Shows as List <ITraktSyncWatchlistPostShow>)?.Add(watchlistShow); } return(this); }