Пример #1
0
        /// <inheritdoc />
        public async Task <int> RemoveDesignatedChannelByIdAsync(long designationId)
        {
            AuthorizationService.RequireClaims(AuthorizationClaim.DesignatedChannelMappingDelete);

            using (var transaction = await DesignatedChannelMappingRepository.BeginDeleteTransactionAsync())
            {
                var deletedCount = await DesignatedChannelMappingRepository.DeleteAsync(new DesignatedChannelMappingSearchCriteria()
                {
                    Id        = designationId,
                    IsDeleted = false
                }, AuthorizationService.CurrentUserId.Value);

                if (deletedCount == 0)
                {
                    throw new InvalidOperationException($"No designations with id {designationId} found.");
                }

                transaction.Commit();
                return(deletedCount);
            }
        }
Пример #2
0
        /// <inheritdoc />
        public async Task <int> RemoveDesignatedChannelAsync(IGuild guild, IMessageChannel logChannel, DesignatedChannelType type)
        {
            AuthorizationService.RequireClaims(AuthorizationClaim.DesignatedChannelMappingDelete);

            using (var transaction = await DesignatedChannelMappingRepository.BeginDeleteTransactionAsync())
            {
                var deletedCount = await DesignatedChannelMappingRepository.DeleteAsync(new DesignatedChannelMappingSearchCriteria()
                {
                    GuildId   = guild.Id,
                    ChannelId = logChannel.Id,
                    IsDeleted = false,
                    Type      = type
                }, AuthorizationService.CurrentUserId.Value);

                if (deletedCount == 0)
                {
                    throw new InvalidOperationException($"{logChannel.Name} in {guild.Name} is not assigned to {type}");
                }

                transaction.Commit();
                return(deletedCount);
            }
        }