Esempio n. 1
0
 /// <inheritdoc />
 public Task <bool> AnyDesignatedChannelAsync(ulong guildId, DesignatedChannelType type)
 => DesignatedChannelMappingRepository.AnyAsync(new DesignatedChannelMappingSearchCriteria()
 {
     GuildId   = guildId,
     Type      = type,
     IsDeleted = false
 });
Esempio n. 2
0
 /// <inheritdoc />
 public Task <IReadOnlyCollection <ulong> > GetDesignatedChannelIdsAsync(ulong guildId, DesignatedChannelType type)
 => DesignatedChannelMappingRepository.SearchChannelIdsAsync(new DesignatedChannelMappingSearchCriteria()
 {
     GuildId   = guildId,
     Type      = type,
     IsDeleted = false
 });
Esempio n. 3
0
        /// <inheritdoc />
        public async Task AddDesignatedChannelAsync(IGuild guild, IMessageChannel logChannel, DesignatedChannelType type)
        {
            AuthorizationService.RequireClaims(AuthorizationClaim.DesignatedChannelMappingCreate);

            using (var transaction = await DesignatedChannelMappingRepository.BeginCreateTransactionAsync())
            {
                if (await DesignatedChannelMappingRepository.AnyAsync(new DesignatedChannelMappingSearchCriteria()
                {
                    GuildId = guild.Id,
                    ChannelId = logChannel.Id,
                    IsDeleted = false,
                    Type = type
                }))
                {
                    throw new InvalidOperationException($"{logChannel.Name} in {guild.Name} is already assigned to {type}");
                }

                await DesignatedChannelMappingRepository.CreateAsync(new DesignatedChannelMappingCreationData()
                {
                    GuildId     = guild.Id,
                    ChannelId   = logChannel.Id,
                    CreatedById = AuthorizationService.CurrentUserId.Value,
                    Type        = type
                });

                transaction.Commit();
            }
        }
Esempio n. 4
0
        /// <inheritdoc />
        public Task <IReadOnlyCollection <DesignatedChannelMappingBrief> > GetDesignatedChannelsAsync(ulong guildId)
        {
            AuthorizationService.RequireClaims(AuthorizationClaim.DesignatedChannelMappingRead);

            return(DesignatedChannelMappingRepository.SearchBriefsAsync(new DesignatedChannelMappingSearchCriteria()
            {
                GuildId = guildId,
                IsDeleted = false
            }));
        }
Esempio n. 5
0
        /// <inheritdoc />
        public async Task <bool> ChannelHasDesignationAsync(IGuild guild, IChannel channel, DesignatedChannelType designation)
        {
            var foundChannels = await DesignatedChannelMappingRepository.SearchBriefsAsync(new DesignatedChannelMappingSearchCriteria()
            {
                GuildId   = guild.Id,
                Type      = designation,
                ChannelId = channel.Id,
                IsDeleted = false
            });

            return(foundChannels.Any());
        }
 /// <inheritdoc />
 public Task <bool> ChannelHasDesignationAsync(
     ulong guildId,
     ulong channelId,
     DesignatedChannelType designation,
     CancellationToken cancellationToken)
 => DesignatedChannelMappingRepository.AnyAsync(new DesignatedChannelMappingSearchCriteria()
 {
     GuildId   = guildId,
     Type      = designation,
     ChannelId = channelId,
     IsDeleted = false
 }, cancellationToken);
Esempio n. 7
0
        private static (ModixContext, DesignatedChannelMappingRepository) BuildTestContext()
        {
            var modixContext = TestDataContextFactory.BuildTestDataContext(x =>
            {
                x.Users.AddRange(Users.Entities.Clone());
                x.GuildUsers.AddRange(GuildUsers.Entities.Clone());
                x.GuildChannels.AddRange(GuildChannels.Entities.Clone());
                x.DesignatedChannelMappings.AddRange(DesignatedChannelMappings.Entities.Clone());
                x.ConfigurationActions.AddRange(ConfigurationActions.Entities.Where(y => !(y.DesignatedChannelMappingId is null)).Clone());
            });

            var uut = new DesignatedChannelMappingRepository(modixContext);

            return(modixContext, uut);
        }
Esempio n. 8
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);
            }
        }
Esempio n. 9
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);
            }
        }