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