using System.Collections.Generic; using System.Linq; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging.Events; namespace NzbDrone.Core.Extras.Files { public interface IExtraFileRepository : IBasicRepository where TExtraFile : ExtraFile, new() { void DeleteForAuthor(int authorId); void DeleteForBook(int authorId, int bookId); void DeleteForBookFile(int bookFileId); List GetFilesByAuthor(int authorId); List GetFilesByBook(int authorId, int bookId); List GetFilesByBookFile(int bookFileId); TExtraFile FindByPath(int authorId, string path); } public class ExtraFileRepository : BasicRepository, IExtraFileRepository where TExtraFile : ExtraFile, new() { public ExtraFileRepository(IMainDatabase database, IEventAggregator eventAggregator) : base(database, eventAggregator) { } public void DeleteForAuthor(int authorId) { Delete(c => c.AuthorId == authorId); } public void DeleteForBook(int authorId, int bookId) { Delete(c => c.AuthorId == authorId && c.BookId == bookId); } public void DeleteForBookFile(int bookFileId) { Delete(c => c.BookFileId == bookFileId); } public List GetFilesByAuthor(int authorId) { return Query(c => c.AuthorId == authorId); } public List GetFilesByBook(int authorId, int bookId) { return Query(c => c.AuthorId == authorId && c.BookId == bookId); } public List GetFilesByBookFile(int bookFileId) { return Query(c => c.BookFileId == bookFileId); } public TExtraFile FindByPath(int authorId, string path) { return Query(c => c.AuthorId == authorId && c.RelativePath == path).SingleOrDefault(); } } }