using ErsatzTV.Core.Api.Graphics; using ErsatzTV.Core.Domain; using ErsatzTV.Core.Graphics; using ErsatzTV.Infrastructure.Data; using Microsoft.EntityFrameworkCore; using static ErsatzTV.Application.Graphics.Mapper; namespace ErsatzTV.Application.Graphics; public class GetAllGraphicsElementsForApiHandler(IDbContextFactory dbContextFactory) : IRequestHandler> { public async Task> Handle( GetAllGraphicsElementsForApi request, CancellationToken cancellationToken) { await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); List graphicsElements = await dbContext.GraphicsElements .AsNoTracking() .ToListAsync(cancellationToken); return graphicsElements .Select(e => new { Vm = ProjectToViewModel(e), BuiltIn = Path.GetFileName(e.Path) == GraphicsElementDefaults.OnNowNextFileName }) .OrderBy(x => x.Vm.Name == x.Vm.FileName) .ThenBy(x => x.Vm.Name) .Select(x => new GraphicsElementResponseModel(x.Vm.Id, x.Vm.Name, x.BuiltIn)) .ToList(); } }