public Task Load(IResource obj, string memberName, bool force = false) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } object existingValue = obj.GetType() .GetProperties() .FirstOrDefault(x => string.Equals(x.Name, memberName, StringComparison.InvariantCultureIgnoreCase)) ?.GetValue(obj); if (existingValue != null && !force) { return(Task.CompletedTask); } return((obj, member : memberName) switch { (Library l, nameof(Library.Providers)) => ProviderRepository .GetAll(x => x.Libraries.Any(y => y.ID == obj.ID)) .Then(x => l.Providers = x), (Library l, nameof(Library.Shows)) => ShowRepository .GetAll(x => x.Libraries.Any(y => y.ID == obj.ID)) .Then(x => l.Shows = x), (Library l, nameof(Library.Collections)) => CollectionRepository .GetAll(x => x.Libraries.Any(y => y.ID == obj.ID)) .Then(x => l.Collections = x), (Collection c, nameof(Collection.ExternalIDs)) => _SetRelation(c, ProviderRepository.GetMetadataID <Collection>(x => x.ResourceID == obj.ID), (x, y) => x.ExternalIDs = y, (x, y) => { x.ResourceID = y.ID; }), (Collection c, nameof(Collection.Shows)) => ShowRepository .GetAll(x => x.Collections.Any(y => y.ID == obj.ID)) .Then(x => c.Shows = x), (Collection c, nameof(Collection.Libraries)) => LibraryRepository .GetAll(x => x.Collections.Any(y => y.ID == obj.ID)) .Then(x => c.Libraries = x), (Show s, nameof(Show.ExternalIDs)) => _SetRelation(s, ProviderRepository.GetMetadataID <Show>(x => x.ResourceID == obj.ID), (x, y) => x.ExternalIDs = y, (x, y) => { x.ResourceID = y.ID; }), (Show s, nameof(Show.Genres)) => GenreRepository .GetAll(x => x.Shows.Any(y => y.ID == obj.ID)) .Then(x => s.Genres = x), (Show s, nameof(Show.People)) => PeopleRepository .GetFromShow(obj.ID) .Then(x => s.People = x), (Show s, nameof(Show.Seasons)) => _SetRelation(s, SeasonRepository.GetAll(x => x.Show.ID == obj.ID), (x, y) => x.Seasons = y, (x, y) => { x.Show = y; x.ShowID = y.ID; }), (Show s, nameof(Show.Episodes)) => _SetRelation(s, EpisodeRepository.GetAll(x => x.Show.ID == obj.ID), (x, y) => x.Episodes = y, (x, y) => { x.Show = y; x.ShowID = y.ID; }), (Show s, nameof(Show.Libraries)) => LibraryRepository .GetAll(x => x.Shows.Any(y => y.ID == obj.ID)) .Then(x => s.Libraries = x), (Show s, nameof(Show.Collections)) => CollectionRepository .GetAll(x => x.Shows.Any(y => y.ID == obj.ID)) .Then(x => s.Collections = x), (Show s, nameof(Show.Studio)) => StudioRepository .GetOrDefault(x => x.Shows.Any(y => y.ID == obj.ID)) .Then(x => { s.Studio = x; s.StudioID = x?.ID ?? 0; }), (Season s, nameof(Season.ExternalIDs)) => _SetRelation(s, ProviderRepository.GetMetadataID <Season>(x => x.ResourceID == obj.ID), (x, y) => x.ExternalIDs = y, (x, y) => { x.ResourceID = y.ID; }), (Season s, nameof(Season.Episodes)) => _SetRelation(s, EpisodeRepository.GetAll(x => x.Season.ID == obj.ID), (x, y) => x.Episodes = y, (x, y) => { x.Season = y; x.SeasonID = y.ID; }), (Season s, nameof(Season.Show)) => ShowRepository .GetOrDefault(x => x.Seasons.Any(y => y.ID == obj.ID)) .Then(x => { s.Show = x; s.ShowID = x?.ID ?? 0; }), (Episode e, nameof(Episode.ExternalIDs)) => _SetRelation(e, ProviderRepository.GetMetadataID <Episode>(x => x.ResourceID == obj.ID), (x, y) => x.ExternalIDs = y, (x, y) => { x.ResourceID = y.ID; }), (Episode e, nameof(Episode.Tracks)) => _SetRelation(e, TrackRepository.GetAll(x => x.Episode.ID == obj.ID), (x, y) => x.Tracks = y, (x, y) => { x.Episode = y; x.EpisodeID = y.ID; }), (Episode e, nameof(Episode.Show)) => ShowRepository .GetOrDefault(x => x.Episodes.Any(y => y.ID == obj.ID)) .Then(x => { e.Show = x; e.ShowID = x?.ID ?? 0; }), (Episode e, nameof(Episode.Season)) => SeasonRepository .GetOrDefault(x => x.Episodes.Any(y => y.ID == e.ID)) .Then(x => { e.Season = x; e.SeasonID = x?.ID ?? 0; }), (Track t, nameof(Track.Episode)) => EpisodeRepository .GetOrDefault(x => x.Tracks.Any(y => y.ID == obj.ID)) .Then(x => { t.Episode = x; t.EpisodeID = x?.ID ?? 0; }), (Genre g, nameof(Genre.Shows)) => ShowRepository .GetAll(x => x.Genres.Any(y => y.ID == obj.ID)) .Then(x => g.Shows = x), (Studio s, nameof(Studio.Shows)) => ShowRepository .GetAll(x => x.Studio.ID == obj.ID) .Then(x => s.Shows = x), (Studio s, nameof(Studio.ExternalIDs)) => _SetRelation(s, ProviderRepository.GetMetadataID <Studio>(x => x.ResourceID == obj.ID), (x, y) => x.ExternalIDs = y, (x, y) => { x.ResourceID = y.ID; }), (People p, nameof(People.ExternalIDs)) => _SetRelation(p, ProviderRepository.GetMetadataID <People>(x => x.ResourceID == obj.ID), (x, y) => x.ExternalIDs = y, (x, y) => { x.ResourceID = y.ID; }), (People p, nameof(People.Roles)) => PeopleRepository .GetFromPeople(obj.ID) .Then(x => p.Roles = x), (Provider p, nameof(Provider.Libraries)) => LibraryRepository .GetAll(x => x.Providers.Any(y => y.ID == obj.ID)) .Then(x => p.Libraries = x), _ => throw new ArgumentException($"Couldn't find a way to load {memberName} of {obj.Slug}.") });
/// <inheritdoc /> public async Task <Season> GetOrDefault(string showSlug, int seasonNumber) { return(await SeasonRepository.GetOrDefault(showSlug, seasonNumber)); }
/// <inheritdoc /> public Task <Season> Get(string showSlug, int seasonNumber) { return(SeasonRepository.Get(showSlug, seasonNumber)); }
/// <inheritdoc /> public async Task <Season> GetOrDefault(int showID, int seasonNumber) { return(await SeasonRepository.GetOrDefault(showID, seasonNumber)); }
/// <inheritdoc /> public Task <Season> Get(int showID, int seasonNumber) { return(SeasonRepository.Get(showID, seasonNumber)); }