42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using DigitalOps.Authority.Services;
|
|
using DigitalOps.Authority.Validators;
|
|
using DigitalOps.CQRS.Services.Project;
|
|
using DigitalOps.CQRS.Services.Project.Options;
|
|
using DigitalOps.Dal;
|
|
using DigitalOps.Dal.DbEntity;
|
|
using FluentValidation;
|
|
using OpenHarbor.CQRS.Abstractions;
|
|
|
|
namespace DigitalOps.CQRS.Commands.Project;
|
|
|
|
public class AddProjectCommand
|
|
{
|
|
public long ClientId { get; set; }
|
|
public required string Name { get; set; }
|
|
}
|
|
|
|
public class AddProjectCommandHandler(ProjectService projectService) : ICommandHandler<AddProjectCommand>
|
|
{
|
|
public async Task HandleAsync(AddProjectCommand command, CancellationToken cancellationToken = new CancellationToken())
|
|
{
|
|
await projectService.AddProjectAsync(new AddProjectOptions
|
|
{
|
|
Name = command.Name,
|
|
ClientId = command.ClientId,
|
|
}, cancellationToken);
|
|
}
|
|
}
|
|
|
|
public class AddProjectCommandValidator : AbstractValidator<AddProjectCommand>
|
|
{
|
|
public AddProjectCommandValidator(MainDbContext dbContext, UserIdentityService userIdentityService)
|
|
{
|
|
RuleFor(command => command.Name)
|
|
.NotEmpty()
|
|
.MinimumLength(3);
|
|
|
|
RuleFor(command => command.ClientId)
|
|
.NotEmpty()
|
|
.SetValidator(new HasAccessToClientValidator(OrganizationRole.Member, dbContext, userIdentityService));
|
|
}
|
|
} |