using Microsoft.EntityFrameworkCore; using OliverBooth.Common.Data.Web; using OliverBooth.Common.Services; using OliverBooth.Data.Web; namespace OliverBooth.Services; internal sealed class ReadingListService : IReadingListService { private readonly IDbContextFactory _dbContextFactory; /// /// Initializes a new instance of the class. /// /// The database context factory. public ReadingListService(IDbContextFactory dbContextFactory) { _dbContextFactory = dbContextFactory; } /// /// Gets the books in the reading list with the specified state. /// /// The state. /// A collection of books in the specified state. public IReadOnlyCollection GetBooks(BookState state) { using WebContext context = _dbContextFactory.CreateDbContext(); return state == (BookState)(-1) ? context.Books.ToArray() : context.Books.Where(b => b.State == state).ToArray(); } }