using MediatR; using Modules.Library.Application.Gateways; using Modules.Library.Domain.Entities.MediaContent.Items.Anime; namespace Modules.Library.Application.Commands.Anime.Season.Properties.Genre; public class AddGenreCommand : IRequest { public Guid TitleId { get; set; } public Guid SeasonId { get; set; } public Guid GenreId { get; set; } public decimal? Proportion { get; set; } } public class AddGenreCommandHandler(IAnimeTitleGateway titleGateway, IGenreGateway genreGateway) : IRequestHandler { public async Task Handle(AddGenreCommand request, CancellationToken cancellationToken) { var title = await titleGateway.GetById(request.TitleId); if (!await genreGateway.IsGenreExists(request.GenreId)) throw new Exception("NotFound"); var season = title.Items.OfType().FirstOrDefault(q => q.Id == request.SeasonId) ?? throw new Exception("Season not found"); season.CommonProperties.AddGenre(request.GenreId, request.Proportion); await titleGateway.Update(title); return Unit.Value; } }