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

23 lines
720 B
C#

using MediatR;
using Modules.Library.Application.Gateways;
namespace Modules.Library.Application.Commands.Anime.Title.Properties;
public class SetCompletedCommand : IRequest<Unit>
{
public Guid TitleId { get; set; }
public bool Value { get; set; }
}
public class SetCompletedCommandHandler(IAnimeTitleGateway titleGateway) : IRequestHandler<SetCompletedCommand, Unit>
{
public async Task<Unit> Handle(SetCompletedCommand request, CancellationToken cancellationToken)
{
var title = await titleGateway.GetById(request.TitleId);
if (request.Value) title.SetCompleted();
else title.SetNotCompleted();
await titleGateway.Update(title);
return Unit.Value;
}
}