Files
ersatztv/ErsatzTV.Application/Scheduling/Commands/DeleteBlockGroupHandler.cs
Jason Dove dcbe4837bf first pass at block scheduling (#1548)
* add blocks, block groups

* basic block and block item editing

* add template groups and basic template editing (name)

* add blocks to template calendar

* edit playout templates

* add calendar preview to playout templates

* add basic block playout building

* add mysql migration

* update changelog
2024-01-13 22:01:21 -06:00

30 lines
1.1 KiB
C#

using ErsatzTV.Core;
using ErsatzTV.Core.Domain.Scheduling;
using ErsatzTV.Infrastructure.Data;
using ErsatzTV.Infrastructure.Extensions;
using Microsoft.EntityFrameworkCore;
namespace ErsatzTV.Application.Scheduling;
public class DeleteBlockGroupHandler(IDbContextFactory<TvContext> dbContextFactory)
: IRequestHandler<DeleteBlockGroup, Option<BaseError>>
{
public async Task<Option<BaseError>> Handle(DeleteBlockGroup request, CancellationToken cancellationToken)
{
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
Option<BlockGroup> maybeBlockGroup = await dbContext.BlockGroups
.SelectOneAsync(p => p.Id, p => p.Id == request.BlockGroupId);
foreach (BlockGroup blockGroup in maybeBlockGroup)
{
dbContext.BlockGroups.Remove(blockGroup);
await dbContext.SaveChangesAsync(cancellationToken);
}
return maybeBlockGroup.Match(
_ => Option<BaseError>.None,
() => BaseError.New($"BlockGroup {request.BlockGroupId} does not exist."));
}
}