コード例 #1
0
        public async Task <Guid> AddRole(AddRoleCommand command, CancellationToken cancellationToken)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            command.EnsureIsValid();

            var persistedRole = await authorizationRepository.GetRoleByName(command.Name, cancellationToken).ConfigureAwait(false);

            if (persistedRole is not null)
            {
                throw new BusinessException(Messages.RoleAlreadyExist);
            }

            var role = new Role()
            {
                Name        = command.Name,
                Description = command.Description
            };

            await authorizationRepository.AddRole(role, cancellationToken).ConfigureAwait(false);

            return(role.Id);
        }