30 lines
1.2 KiB
C#
30 lines
1.2 KiB
C#
using MediatR;
|
|
using Modules.Library.Application.Gateways;
|
|
using Modules.Library.Domain.Entities.MediaContent.CommonProperties;
|
|
using Modules.Library.Domain.Entities.MediaContent.Items.Anime;
|
|
|
|
namespace Modules.Library.Application.Commands.Anime.Season.Properties.Name;
|
|
|
|
public class EditNameCommand : IRequest<Unit>
|
|
{
|
|
public Guid TitleId { get; set; }
|
|
public Guid SeasonId { get; set; }
|
|
public CommonModels.NameType NameType { get; set; }
|
|
public Guid LanguageId { get; set; }
|
|
public string Value { get; set; } = default!;
|
|
public string NewValue { get; set; } = default!;
|
|
|
|
}
|
|
|
|
public class EditNameCommandHandler(IAnimeTitleGateway titleGateway) : IRequestHandler<EditNameCommand, Unit>
|
|
{
|
|
public async Task<Unit> Handle(EditNameCommand 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.SetNameValue(new NameItem((NameType)request.NameType, request.LanguageId, request.Value), request.NewValue);
|
|
await titleGateway.Update(title);
|
|
return Unit.Value;
|
|
}
|
|
} |