MyBookmark/Modules.Library.Application/Commands/Anime/Season/Properties/Preview/DeletePreviewCommand.cs
2024-09-23 03:00:50 +03:00

24 lines
918 B
C#

using MediatR;
using Modules.Library.Application.Gateways;
using Modules.Library.Domain.Entities.MediaContent.Items.Anime;
namespace Modules.Library.Application.Commands.Anime.Season.Properties.Preview;
public class DeletePreviewCommand : IRequest<Unit>
{
public Guid TitleId { get; set; }
public Guid SeasonId { get; set; }
}
public class DeletePreviewCommandHandler(IAnimeTitleGateway titleGateway) : IRequestHandler<DeletePreviewCommand, Unit>
{
public async Task<Unit> Handle(DeletePreviewCommand request, CancellationToken cancellationToken)
{
var title = await titleGateway.GetById(request.TitleId);
var season = title.Items.OfType<AnimeSeason>().FirstOrDefault(q => q.Id == request.SeasonId) ??
throw new Exception("Season not found");
season.CommonProperties.DeletePreview();
await titleGateway.Update(title);
return Unit.Value;
}
}