MyBookmark/Modules.Library.Application/Commands/Dictionaries/Genre/SetGenreNameCommand.cs
2024-09-23 03:00:50 +03:00

20 lines
733 B
C#

using MediatR;
using Modules.Library.Application.Gateways;
namespace Modules.Library.Application.Commands.Dictionaries.Genre;
public class SetGenreNameCommand : IRequest<Unit>
{
public Guid Id { get; set; } = default!;
public string Name { get; set; } = default!;
}
public class SetGenreNameCommandHandler(IGenreGateway genreGateway) : IRequestHandler<SetGenreNameCommand, Unit>
{
public async Task<Unit> Handle(SetGenreNameCommand request, CancellationToken cancellationToken)
{
if (await genreGateway.IsGenreExists(request.Name, request.Id)) throw new Exception("Genre with the same name already exist");
await genreGateway.SetName(request.Id, request.Name);
return Unit.Value;
}
}