using MediaBrowser.Controller.Entities; using MediaBrowser.Model.Entities; using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace MediaBrowser.Controller.Persistence { /// /// Provides an interface to implement an Item repository /// public interface IItemRepository : IRepository { /// /// Saves an item /// /// The item. /// The cancellation token. /// Task. Task SaveItem(BaseItem item, CancellationToken cancellationToken); /// /// Gets the critic reviews. /// /// The item id. /// Task{IEnumerable{ItemReview}}. Task> GetCriticReviews(Guid itemId); /// /// Saves the critic reviews. /// /// The item id. /// The critic reviews. /// Task. Task SaveCriticReviews(Guid itemId, IEnumerable criticReviews); /// /// Saves the items. /// /// The items. /// The cancellation token. /// Task. Task SaveItems(IEnumerable items, CancellationToken cancellationToken); /// /// Retrieves the item. /// /// The id. /// The type. /// BaseItem. BaseItem RetrieveItem(Guid id, Type type); /// /// Gets chapters for an item /// /// /// IEnumerable GetChapters(Guid id); /// /// Gets a single chapter for an item /// /// /// /// ChapterInfo GetChapter(Guid id, int index); /// /// Saves the chapters. /// /// The id. /// The chapters. /// The cancellation token. /// Task. Task SaveChapters(Guid id, IEnumerable chapters, CancellationToken cancellationToken); } /// /// Class ItemRepositoryExtensions /// public static class ItemRepositoryExtensions { /// /// Retrieves the item. /// /// /// The repository. /// The id. /// ``0. public static T RetrieveItem(this IItemRepository repository, Guid id) where T : BaseItem, new() { return repository.RetrieveItem(id, typeof(T)) as T; } /// /// Retrieves the item. /// /// /// The repository. /// The id list. /// IEnumerable{``0}. public static IEnumerable RetrieveItems(this IItemRepository repository, IEnumerable idList) where T : BaseItem, new() { return idList.Select(repository.RetrieveItem).Where(i => i != null); } } }