using Application.Abstractions.Data; using Application.Abstractions.Messaging; using Microsoft.EntityFrameworkCore; namespace Application.Features.Admin.Channel.List.Delete; public sealed class Handler(IAppDbContext db) : ICommandHandler { public async Task Handle(Command request, CancellationToken ct) { if (request.IDs is null || request.IDs.Length < 1) { return; } var list = await db.Channel.Where(c => request.IDs.Contains(c.ID)).ToListAsync(ct); if (list.Count < 1) { return; } if (await db.Order.AnyAsync(c => c.ChannelID.HasValue && request.IDs.Contains(c.ChannelID.Value), ct)) throw new InvalidOperationException("상점 주문 내역이 존재하는 채널은 삭제할 수 없습니다."); db.Channel.RemoveRange(list); await db.SaveChangesAsync(ct); } }