18 lines
639 B
C#
18 lines
639 B
C#
using MediatR;
|
|
using Modules.Library.Application.Gateways;
|
|
|
|
namespace Modules.Library.Application.Commands.Dictionaries.Genre;
|
|
|
|
public class CreateGenreCommand : IRequest<Guid>
|
|
{
|
|
public string Name { get; set; } = default!;
|
|
}
|
|
|
|
public class CreateGenreCommandHandler(IGenreGateway genreGateway) : IRequestHandler<CreateGenreCommand, Guid>
|
|
{
|
|
public async Task<Guid> Handle(CreateGenreCommand request, CancellationToken cancellationToken)
|
|
{
|
|
if (await genreGateway.IsGenreExists(request.Name)) throw new Exception("Genre with the same name already exist");
|
|
return await genreGateway.Create(request.Name);
|
|
}
|
|
} |