/// <summary>Adds a <see cref="TraktShow" />, which will be added to the user custom list items post.</summary> /// <param name="show">The Trakt show, which will be added.</param> /// <param name="season"> /// A season number for a season in the given show. The complete season will be added to the custom list. /// </param> /// <param name="seasons"> /// An optional array of season numbers for seasons in the given show. /// The complete seasons will be added to the custom list. /// </param> /// <returns>The current <see cref="TraktUserCustomListItemsPostBuilder" /> 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 is below zero. /// </exception> public TraktUserCustomListItemsPostBuilder AddShow(TraktShow show, int season, params int[] seasons) { ValidateShow(show); EnsureShowsListExists(); var seasonsToAdd = new int[seasons.Length + 1]; seasonsToAdd[0] = season; seasons.CopyTo(seasonsToAdd, 1); var showSeasons = new List <TraktUserCustomListItemsPostShowSeason>(); for (int i = 0; i < seasonsToAdd.Length; i++) { if (seasonsToAdd[i] < 0) { throw new ArgumentOutOfRangeException("at least one season number not valid"); } showSeasons.Add(new TraktUserCustomListItemsPostShowSeason { Number = seasonsToAdd[i] }); } var existingShow = _listItemsPost.Shows.Where(s => s.Ids == show.Ids).FirstOrDefault(); if (existingShow != null) { existingShow.Seasons = showSeasons; } else { var listItemsShow = new TraktUserCustomListItemsPostShow(); listItemsShow.Ids = show.Ids; listItemsShow.Seasons = showSeasons; (_listItemsPost.Shows as List <TraktUserCustomListItemsPostShow>).Add(listItemsShow); } return(this); }
/// <summary>Adds a <see cref="TraktShow" />, which will be added to the user custom list items 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 custom list. /// </param> /// <returns>The current <see cref="TraktUserCustomListItemsPostBuilder" /> 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 TraktUserCustomListItemsPostBuilder AddShow(TraktShow show, PostSeasons seasons) { ValidateShow(show); if (seasons == null) { throw new ArgumentNullException(nameof(seasons)); } EnsureShowsListExists(); var showSeasons = new List <TraktUserCustomListItemsPostShowSeason>(); foreach (var season in seasons) { if (season.Number < 0) { throw new ArgumentOutOfRangeException("at least one season number not valid", nameof(season)); } var showSingleSeason = new TraktUserCustomListItemsPostShowSeason { Number = season.Number }; if (season.Episodes != null && season.Episodes.Count() > 0) { var showEpisodes = new List <TraktUserCustomListItemsPostShowEpisode>(); foreach (var episode in season.Episodes) { if (episode < 0) { throw new ArgumentOutOfRangeException("at least one episode number not valid", nameof(seasons)); } showEpisodes.Add(new TraktUserCustomListItemsPostShowEpisode { Number = episode }); } showSingleSeason.Episodes = showEpisodes; } showSeasons.Add(showSingleSeason); } var existingShow = _listItemsPost.Shows.Where(s => s.Ids == show.Ids).FirstOrDefault(); if (existingShow != null) { existingShow.Seasons = showSeasons; } else { var listItemsShow = new TraktUserCustomListItemsPostShow(); listItemsShow.Ids = show.Ids; listItemsShow.Seasons = showSeasons; (_listItemsPost.Shows as List <TraktUserCustomListItemsPostShow>).Add(listItemsShow); } return(this); }