public static async Task SetAdminRoles(ulong guildId, ulong[] roleIds) { try { using (var DbContext = new SqliteDbContext()) { CreateGuildConfig(guildId).GetAwaiter().GetResult();//guild config not found GuildConfigEntity guild = DbContext.GuildConfig.Where(y => y.GuildId == guildId).FirstOrDefault(); DbContext.AdminRoles.RemoveRange(guild.AdminRoles); foreach (ulong role in roleIds) { DbContext.AdminRoles.Add(new AdminRoleEntity() { GuildId = guild.GuildId, RoleId = role }); } await DbContext.SaveChangesAsync(); } } catch { //TODO: Log exception, more specified description throw; } }
public async Task UpdateGuildConfigAsync(GuildConfigEntity guildConfig) { await using var connection = _config.GetGuildConfigConnection(); await connection.OpenAsync().ConfigureAwait(false); await connection.UpdateAsync(guildConfig).ConfigureAwait(false); }
public static GuildConfig ToModel(this GuildConfigEntity entity) { return(new GuildConfig { Id = (ulong)entity.Id, AutoDelete = entity.AutoDelete, GuessTime = entity.GuessTime, HangmanTime = entity.HangmanTime, Inline = entity.Inline, Minimal = entity.Minimal, Prefix = entity.Prefix, HangmanAllowWords = entity.HangmanAllowWords, }); }
public async Task InsertGuildConfigAsync_ExpectSuccess() { var expected = new GuildConfigEntity { Id = 1337420 }; //HAHa FUNNy NUmbeR *insert mocking spongebob meme await _guildConfigRepo.InsertGuildConfigAsync(expected); await using var connection = new NpgsqlConnection(Config.Instance.DbConnectionString !.Guilds); var actual = await connection.ExecuteScalarAsync <decimal>("select id from configs where id = @id", new { id = expected.Id }); Assert.Equal(expected.Id, actual); await connection.DeleteAsync(expected); }
public static async Task RemoveAdminRoles(ulong guildId, ulong[] roleIds) { try { using (var DbContext = new SqliteDbContext()) { if (DbContext.GuildConfig.Where(x => x.GuildId == guildId).Count() < 1) { CreateGuildConfig(guildId).GetAwaiter().GetResult();//guild config not found return; } GuildConfigEntity guild = DbContext.GuildConfig.Where(y => y.GuildId == guildId).FirstOrDefault(); DbContext.AdminRoles.RemoveRange(guild.AdminRoles.Where(x => roleIds.Any(z => z == x.RoleId))); await DbContext.SaveChangesAsync(); } } catch { //TODO: Log exception, more specified description throw; } }