using ErsatzTV.Core.Api.Graphics; using ErsatzTV.Core.Domain; 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 .Map(ProjectToViewModel) .OrderBy(e => e.Name == e.FileName) .ThenBy(e => e.Name) .Select(vm => new GraphicsElementResponseModel(vm.Id, vm.Name)) .ToList(); } }