44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
|
|
using Books.Api.Domain.UserAccess;
|
||
|
|
using EventFlow.Commands;
|
||
|
|
|
||
|
|
namespace Books.Api.Commands.UserAccess;
|
||
|
|
|
||
|
|
public class GrantUserCompanyAccessCommandHandler
|
||
|
|
: CommandHandler<UserCompanyAccessAggregate, UserCompanyAccessId, GrantUserCompanyAccessCommand>
|
||
|
|
{
|
||
|
|
public override Task ExecuteAsync(
|
||
|
|
UserCompanyAccessAggregate aggregate,
|
||
|
|
GrantUserCompanyAccessCommand command,
|
||
|
|
CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
aggregate.GrantAccess(command.UserId, command.CompanyId, command.Role, command.GrantedBy);
|
||
|
|
return Task.CompletedTask;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public class ChangeUserCompanyAccessRoleCommandHandler
|
||
|
|
: CommandHandler<UserCompanyAccessAggregate, UserCompanyAccessId, ChangeUserCompanyAccessRoleCommand>
|
||
|
|
{
|
||
|
|
public override Task ExecuteAsync(
|
||
|
|
UserCompanyAccessAggregate aggregate,
|
||
|
|
ChangeUserCompanyAccessRoleCommand command,
|
||
|
|
CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
aggregate.ChangeRole(command.NewRole, command.ChangedBy);
|
||
|
|
return Task.CompletedTask;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public class RevokeUserCompanyAccessCommandHandler
|
||
|
|
: CommandHandler<UserCompanyAccessAggregate, UserCompanyAccessId, RevokeUserCompanyAccessCommand>
|
||
|
|
{
|
||
|
|
public override Task ExecuteAsync(
|
||
|
|
UserCompanyAccessAggregate aggregate,
|
||
|
|
RevokeUserCompanyAccessCommand command,
|
||
|
|
CancellationToken cancellationToken)
|
||
|
|
{
|
||
|
|
aggregate.RevokeAccess(command.RevokedBy);
|
||
|
|
return Task.CompletedTask;
|
||
|
|
}
|
||
|
|
}
|