public async Task <OperationResult> UpdateAsync(
            long guildId,
            CharacterGuildUpdateModel updateModel,
            CancellationToken cancellationToken)
        {
            using var logScope = OperationLogMessages.BeginOperationScope(_logger, this);
            OperationLogMessages.OperationPerforming(_logger);

            OperationLogMessages.OperationAuthorizing(_logger);
            var authResult = await _authorizationService.RequirePermissionsAsync(
                new[] { (int)CharacterAdministrationPermission.ManageGuilds },
                cancellationToken);

            if (authResult.IsFailure)
            {
                OperationLogMessages.OperationNotAuthorized(_logger);
                return(authResult.Error);
            }
            OperationLogMessages.OperationAuthorized(_logger);

            var performedById = _authenticationService.CurrentTicket !.UserId;

            var result = await _characterGuildsService.UpdateAsync(guildId, updateModel, performedById, cancellationToken);

            OperationLogMessages.OperationPerformed(_logger, result);

            return(result);
        }
示例#2
0
 public static void CharacterGuildUpdating(
     ILogger logger,
     long guildId,
     CharacterGuildUpdateModel updateModel,
     ulong performedById)
 => _characterGuildUpdating.Invoke(
     logger,
     guildId,
     updateModel,
     performedById);
        public async Task <OperationResult> UpdateAsync(
            long guildId,
            CharacterGuildUpdateModel updateModel,
            ulong performedById,
            CancellationToken cancellationToken)
        {
            CharactersLogMessages.CharacterGuildUpdating(_logger, guildId, updateModel, performedById);

            using var transactionScope = _transactionScopeFactory.CreateScope();
            TransactionsLogMessages.TransactionScopeCreated(_logger);

            var nameValidationResult = await ValidateNameAsync(updateModel.Name, guildId, cancellationToken);

            if (nameValidationResult.IsFailure)
            {
                CharactersLogMessages.CharacterGuildNameValidationFailed(_logger, updateModel.Name, nameValidationResult);
                return(nameValidationResult);
            }
            CharactersLogMessages.CharacterGuildNameValidationSucceeded(_logger, updateModel.Name);

            var now = _systemClock.UtcNow;

            var actionId = await _auditableActionsRepository.CreateAsync(
                (int)CharacterManagementAdministrationActionType.GuildModified,
                now,
                performedById,
                cancellationToken);

            AuditingLogMessages.AuditingActionCreated(_logger, actionId);

            var updateResult = await _characterGuildsRepository.UpdateAsync(
                guildId : guildId,
                actionId : actionId,
                name : updateModel.Name,
                cancellationToken : cancellationToken);

            if (updateResult.IsFailure)
            {
                CharactersLogMessages.CharacterGuildUpdateFailed(_logger, guildId, updateResult);
                return(updateResult);
            }
            CharactersLogMessages.CharacterGuildUpdated(_logger, guildId);

            transactionScope.Complete();
            TransactionsLogMessages.TransactionScopeCommitted(_logger);

            return(OperationResult.Success);
        }