32 lines
918 B
C#
32 lines
918 B
C#
using DigitalOps.CQRS.Services.Organization;
|
|
using DigitalOps.CQRS.Services.Organization.Options;
|
|
using FluentValidation;
|
|
using OpenHarbor.CQRS.Abstractions;
|
|
|
|
namespace DigitalOps.CQRS.Commands.Organization;
|
|
|
|
public class AddOrganizationCommand
|
|
{
|
|
public required string Name { get; set; }
|
|
}
|
|
|
|
public class AddOrganizationCommandHandler(OrganizationService organizationService) : ICommandHandler<AddOrganizationCommand>
|
|
{
|
|
public async Task HandleAsync(AddOrganizationCommand command, CancellationToken cancellationToken = new CancellationToken())
|
|
{
|
|
await organizationService.RegisterOrganizationAsync(new RegisterOrganizationOptions
|
|
{
|
|
Name = command.Name
|
|
}, cancellationToken);
|
|
}
|
|
}
|
|
|
|
public class AddOrganizationCommandValidator : AbstractValidator<AddOrganizationCommand>
|
|
{
|
|
public AddOrganizationCommandValidator()
|
|
{
|
|
RuleFor(x => x.Name)
|
|
.NotEmpty()
|
|
.MinimumLength(3);
|
|
}
|
|
} |