MyBookmark/Modules.Library.Application/Commands/Anime/Title/Properties/Name/AddNameCommand.cs
2024-09-23 03:00:50 +03:00

26 lines
1.0 KiB
C#

using MediatR;
using Modules.Library.Application.Commands.CommonModels;
using Modules.Library.Application.Gateways;
namespace Modules.Library.Application.Commands.Anime.Title.Properties.Name;
public class AddNameCommand : IRequest<Unit>
{
public Guid TitleId { get; set; }
public NameType NameType { get; set; }
public Guid LanguageId { get; set; }
public string Value { get; set; } = default!;
}
public class AddNameCommandHandler(IAnimeTitleGateway titleGateway, ILanguageGateway languageGateway) : IRequestHandler<AddNameCommand, Unit>
{
public async Task<Unit> Handle(AddNameCommand request, CancellationToken cancellationToken)
{
var title = await titleGateway.GetById(request.TitleId);
var language = await languageGateway.GetLanguageById(request.LanguageId);
title.CommonProperties.AddName((Domain.Entities.MediaContent.CommonProperties.NameType)request.NameType, language.Id, request.Value);
await titleGateway.Update(title);
return Unit.Value;
}
}