mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
1.1 KiB
29 lines
1.1 KiB
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 DeleteDecoGroupHandler(IDbContextFactory<TvContext> dbContextFactory) |
|
: IRequestHandler<DeleteDecoGroup, Option<BaseError>> |
|
{ |
|
public async Task<Option<BaseError>> Handle(DeleteDecoGroup request, CancellationToken cancellationToken) |
|
{ |
|
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); |
|
|
|
Option<DecoGroup> maybeDecoGroup = await dbContext.DecoGroups |
|
.SelectOneAsync(p => p.Id, p => p.Id == request.DecoGroupId); |
|
|
|
foreach (DecoGroup decoGroup in maybeDecoGroup) |
|
{ |
|
dbContext.DecoGroups.Remove(decoGroup); |
|
await dbContext.SaveChangesAsync(cancellationToken); |
|
} |
|
|
|
return maybeDecoGroup.Match( |
|
_ => Option<BaseError>.None, |
|
() => BaseError.New($"DecoGroup {request.DecoGroupId} does not exist.")); |
|
} |
|
}
|
|
|