diff --git a/ChaosBot/ConfigHelpers/ConfigurationRepository.cs b/ChaosBot/ConfigHelpers/ConfigurationRepository.cs index f5d1d1b..ed50f2b 100644 --- a/ChaosBot/ConfigHelpers/ConfigurationRepository.cs +++ b/ChaosBot/ConfigHelpers/ConfigurationRepository.cs @@ -17,7 +17,7 @@ namespace ChaosBot.ConfigHelpers public static T GetValue(string key, ulong guildId, T defaultValue) { - using ChaosbotContext dbContext = new ChaosbotContext(); + using DatabaseContext dbContext = new DatabaseContext(); Models.Configuration config = dbContext.Configuration .SingleOrDefault(c => c.DiscordGuildId == guildId && c.Key == key); if (config == null || string.IsNullOrEmpty(config.SerializedValue)) @@ -27,7 +27,7 @@ namespace ChaosBot.ConfigHelpers public static void SetValue(string key, T value, ulong guildId) { - using ChaosbotContext dbContext = new ChaosbotContext(); + using DatabaseContext dbContext = new DatabaseContext(); Models.Configuration cnfSet = new Models.Configuration(); cnfSet.Key = key; @@ -41,7 +41,7 @@ namespace ChaosBot.ConfigHelpers public static void DeleteValue(string key, ulong guildId) { - using ChaosbotContext dbContext = new ChaosbotContext(); + using DatabaseContext dbContext = new DatabaseContext(); Models.Configuration config = dbContext.Configuration .SingleOrDefault(c => c.DiscordGuildId == guildId && c.Key == key); if (config == null) return; diff --git a/ChaosBot/Models/ChaosbotContext.cs b/ChaosBot/DatabaseContext.cs similarity index 97% rename from ChaosBot/Models/ChaosbotContext.cs rename to ChaosBot/DatabaseContext.cs index 4eb3543..933f59d 100644 --- a/ChaosBot/Models/ChaosbotContext.cs +++ b/ChaosBot/DatabaseContext.cs @@ -1,9 +1,10 @@ +using ChaosBot.Models; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; -namespace ChaosBot.Models +namespace ChaosBot { - public class ChaosbotContext : DbContext + public class DatabaseContext : DbContext { public DbSet LodestoneCharacter { get; set; } public DbSet LodestoneFreeCompany { get; set; } diff --git a/ChaosBot/Discord/Modules/Admin/Role.cs b/ChaosBot/Discord/Modules/Admin/Role.cs index 3e91f7f..0c5ff7e 100644 --- a/ChaosBot/Discord/Modules/Admin/Role.cs +++ b/ChaosBot/Discord/Modules/Admin/Role.cs @@ -60,7 +60,7 @@ namespace ChaosBot.Discord.Modules.Admin { try { - await using (ChaosbotContext dbContext = new ChaosbotContext()) + await using (DatabaseContext dbContext = new DatabaseContext()) { string parameterString = String.Join("", parameters); @@ -134,7 +134,7 @@ namespace ChaosBot.Discord.Modules.Admin { try { - await using (ChaosbotContext dbContext = new ChaosbotContext()) + await using (DatabaseContext dbContext = new DatabaseContext()) { string parameterString = String.Join("", parameters); diff --git a/ChaosBot/Discord/Modules/User/Level.cs b/ChaosBot/Discord/Modules/User/Level.cs index 9c24de4..6141cdc 100644 --- a/ChaosBot/Discord/Modules/User/Level.cs +++ b/ChaosBot/Discord/Modules/User/Level.cs @@ -26,7 +26,7 @@ namespace ChaosBot.Discord.Modules.User embed.Title = $"Current Level Statistics"; sb.AppendLine(); - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { IQueryable ctxUser = dbContext.ExperiencePoints; IQueryable usrXp = ctxUser diff --git a/ChaosBot/Discord/Modules/User/Lodestone.cs b/ChaosBot/Discord/Modules/User/Lodestone.cs index c1ca9c3..6ec68b5 100644 --- a/ChaosBot/Discord/Modules/User/Lodestone.cs +++ b/ChaosBot/Discord/Modules/User/Lodestone.cs @@ -165,7 +165,7 @@ namespace ChaosBot.Discord.Modules.User } bool linked; - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { IQueryable ctxlsChars = dbContext.LodestoneCharacter; IQueryable lsChar = ctxlsChars.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.LodestoneId.Equals(Convert.ToUInt64(character.Character.ID))); @@ -184,7 +184,7 @@ namespace ChaosBot.Discord.Modules.User if (character.Character.Bio.Contains(b64)) { - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { LodestoneCharacter lsChar = new LodestoneCharacter(); diff --git a/ChaosBot/Discord/Modules/User/Points.cs b/ChaosBot/Discord/Modules/User/Points.cs index 264e958..e7dc729 100644 --- a/ChaosBot/Discord/Modules/User/Points.cs +++ b/ChaosBot/Discord/Modules/User/Points.cs @@ -113,7 +113,7 @@ namespace ChaosBot.Discord.Modules.User try { - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { IQueryable points = dbContext.Points; cur = points @@ -135,7 +135,7 @@ namespace ChaosBot.Discord.Modules.User ulong cur = 0; try { - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { IQueryable ctxPoints = dbContext.Points; @@ -180,7 +180,7 @@ namespace ChaosBot.Discord.Modules.User { if (admin) { - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { IQueryable ctxPoints = dbContext.Points; @@ -211,7 +211,7 @@ namespace ChaosBot.Discord.Modules.User } else { - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { IQueryable ctxPoints = dbContext.Points; @@ -276,7 +276,7 @@ namespace ChaosBot.Discord.Modules.User { try { - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { Point usrPoint = new Point(); diff --git a/ChaosBot/Discord/Modules/User/RaffleCmd.cs b/ChaosBot/Discord/Modules/User/RaffleCmd.cs index a8b398c..fd77678 100644 --- a/ChaosBot/Discord/Modules/User/RaffleCmd.cs +++ b/ChaosBot/Discord/Modules/User/RaffleCmd.cs @@ -126,7 +126,7 @@ namespace ChaosBot.Discord.Modules.User try { - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { IQueryable ctxRaffles = dbContext.Raffles; @@ -150,7 +150,7 @@ namespace ChaosBot.Discord.Modules.User { if (admin) { - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { IQueryable ctxRaffles = dbContext.Raffles; @@ -187,7 +187,7 @@ namespace ChaosBot.Discord.Modules.User int cur = 0; try { - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { IQueryable ctxRaffles = dbContext.Raffles; @@ -224,7 +224,7 @@ namespace ChaosBot.Discord.Modules.User { try { - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { IQueryable ctxRaffles = dbContext.Raffles; @@ -258,7 +258,7 @@ namespace ChaosBot.Discord.Modules.User { if(confirm == "confirm") { - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { IQueryable ctxRaffles = dbContext.Raffles; @@ -293,7 +293,7 @@ namespace ChaosBot.Discord.Modules.User { try { - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { IQueryable ctxRaffles = dbContext.Raffles; diff --git a/ChaosBot/Discord/Services/CommandHandler.cs b/ChaosBot/Discord/Services/CommandHandler.cs index 893677c..9d99bd5 100644 --- a/ChaosBot/Discord/Services/CommandHandler.cs +++ b/ChaosBot/Discord/Services/CommandHandler.cs @@ -106,7 +106,7 @@ namespace ChaosBot.Discord.Services { try { - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { Experience newUser = new Experience(); newUser.Amount = 0; @@ -131,7 +131,7 @@ namespace ChaosBot.Discord.Services { try { - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { IQueryable ctxUser = dbContext.ExperiencePoints; IQueryable usrXp = ctxUser diff --git a/ChaosBot/Discord/Services/CustomCommandHandler.cs b/ChaosBot/Discord/Services/CustomCommandHandler.cs index da64597..813e23c 100644 --- a/ChaosBot/Discord/Services/CustomCommandHandler.cs +++ b/ChaosBot/Discord/Services/CustomCommandHandler.cs @@ -15,7 +15,7 @@ namespace ChaosBot.Discord.Services { try { - await using ChaosbotContext dbContext = new ChaosbotContext(); + await using DatabaseContext dbContext = new DatabaseContext(); string command = context.Message.Content.Substring(argPos); IQueryable customCommandQuery = dbContext.CustomCommands; diff --git a/ChaosBot/Discord/Services/ExperienceHandler.cs b/ChaosBot/Discord/Services/ExperienceHandler.cs index 7412c9a..d2bebae 100644 --- a/ChaosBot/Discord/Services/ExperienceHandler.cs +++ b/ChaosBot/Discord/Services/ExperienceHandler.cs @@ -18,7 +18,7 @@ namespace ChaosBot.Discord.Services { if (!CheckModuleEnabled.GetResult(context, "Experience")) return; - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { IQueryable ctxUser = dbContext.ExperiencePoints; IQueryable usrXp = ctxUser diff --git a/ChaosBot/Discord/Services/RoleReactionHandler.cs b/ChaosBot/Discord/Services/RoleReactionHandler.cs index 6d1e13a..5233cd0 100644 --- a/ChaosBot/Discord/Services/RoleReactionHandler.cs +++ b/ChaosBot/Discord/Services/RoleReactionHandler.cs @@ -17,7 +17,7 @@ namespace ChaosBot.Discord.Services if (!(optionalUser.Value is IGuildUser user)) return; if (!(socketMessageChannel is SocketGuildChannel channel)) return; - await using ChaosbotContext dbContext = new ChaosbotContext(); + await using DatabaseContext dbContext = new DatabaseContext(); IQueryable roleReactionsQueryable = dbContext.RoleReactions; List roleReactions = roleReactionsQueryable @@ -47,7 +47,7 @@ namespace ChaosBot.Discord.Services if (!(optionalUser.Value is IGuildUser user)) return; if (!(socketMessageChannel is SocketGuildChannel channel)) return; - await using ChaosbotContext dbContext = new ChaosbotContext(); + await using DatabaseContext dbContext = new DatabaseContext(); IQueryable roleReactionsQueryable = dbContext.RoleReactions; List roleReactions = roleReactionsQueryable diff --git a/ChaosBot/Migrations/20200804195804_LodestoneCharacter.Designer.cs b/ChaosBot/Migrations/20200804195804_LodestoneCharacter.Designer.cs index d7d98d2..da1704f 100644 --- a/ChaosBot/Migrations/20200804195804_LodestoneCharacter.Designer.cs +++ b/ChaosBot/Migrations/20200804195804_LodestoneCharacter.Designer.cs @@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ChaosBot.Migrations { - [DbContext(typeof(ChaosbotContext))] + [DbContext(typeof(DatabaseContext))] [Migration("20200804195804_LodestoneCharacter")] partial class LodestoneCharacter { diff --git a/ChaosBot/Migrations/20200804202834_LodestoneFreeCompany.Designer.cs b/ChaosBot/Migrations/20200804202834_LodestoneFreeCompany.Designer.cs index b659828..e007205 100644 --- a/ChaosBot/Migrations/20200804202834_LodestoneFreeCompany.Designer.cs +++ b/ChaosBot/Migrations/20200804202834_LodestoneFreeCompany.Designer.cs @@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ChaosBot.Migrations { - [DbContext(typeof(ChaosbotContext))] + [DbContext(typeof(DatabaseContext))] [Migration("20200804202834_LodestoneFreeCompany")] partial class LodestoneFreeCompany { diff --git a/ChaosBot/Migrations/20200804203214_Points.Designer.cs b/ChaosBot/Migrations/20200804203214_Points.Designer.cs index 6245ef7..b14a850 100644 --- a/ChaosBot/Migrations/20200804203214_Points.Designer.cs +++ b/ChaosBot/Migrations/20200804203214_Points.Designer.cs @@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ChaosBot.Migrations { - [DbContext(typeof(ChaosbotContext))] + [DbContext(typeof(DatabaseContext))] [Migration("20200804203214_Points")] partial class Points { diff --git a/ChaosBot/Migrations/20200804204404_Raffles.Designer.cs b/ChaosBot/Migrations/20200804204404_Raffles.Designer.cs index 8e9d871..7b6b797 100644 --- a/ChaosBot/Migrations/20200804204404_Raffles.Designer.cs +++ b/ChaosBot/Migrations/20200804204404_Raffles.Designer.cs @@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ChaosBot.Migrations { - [DbContext(typeof(ChaosbotContext))] + [DbContext(typeof(DatabaseContext))] [Migration("20200804204404_Raffles")] partial class Raffles { diff --git a/ChaosBot/Migrations/20200804204734_CommandPermissions.Designer.cs b/ChaosBot/Migrations/20200804204734_CommandPermissions.Designer.cs index fd8e177..edcd67d 100644 --- a/ChaosBot/Migrations/20200804204734_CommandPermissions.Designer.cs +++ b/ChaosBot/Migrations/20200804204734_CommandPermissions.Designer.cs @@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ChaosBot.Migrations { - [DbContext(typeof(ChaosbotContext))] + [DbContext(typeof(DatabaseContext))] [Migration("20200804204734_CommandPermissions")] partial class CommandPermissions { diff --git a/ChaosBot/Migrations/20200804205955_Configuration.Designer.cs b/ChaosBot/Migrations/20200804205955_Configuration.Designer.cs index f088ea8..d018451 100644 --- a/ChaosBot/Migrations/20200804205955_Configuration.Designer.cs +++ b/ChaosBot/Migrations/20200804205955_Configuration.Designer.cs @@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ChaosBot.Migrations { - [DbContext(typeof(ChaosbotContext))] + [DbContext(typeof(DatabaseContext))] [Migration("20200804205955_Configuration")] partial class Configuration { diff --git a/ChaosBot/Migrations/20200804213001_ExperiencePoints.Designer.cs b/ChaosBot/Migrations/20200804213001_ExperiencePoints.Designer.cs index 52ddea9..e1276af 100644 --- a/ChaosBot/Migrations/20200804213001_ExperiencePoints.Designer.cs +++ b/ChaosBot/Migrations/20200804213001_ExperiencePoints.Designer.cs @@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ChaosBot.Migrations { - [DbContext(typeof(ChaosbotContext))] + [DbContext(typeof(DatabaseContext))] [Migration("20200804213001_ExperiencePoints")] partial class ExperiencePoints { diff --git a/ChaosBot/Migrations/20200819203430_RoleReaction.Designer.cs b/ChaosBot/Migrations/20200819203430_RoleReaction.Designer.cs index 6826a1a..df676c2 100644 --- a/ChaosBot/Migrations/20200819203430_RoleReaction.Designer.cs +++ b/ChaosBot/Migrations/20200819203430_RoleReaction.Designer.cs @@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ChaosBot.Migrations { - [DbContext(typeof(ChaosbotContext))] + [DbContext(typeof(DatabaseContext))] [Migration("20200819203430_RoleReaction")] partial class RoleReaction { diff --git a/ChaosBot/Migrations/20200824124830_CustomCommand.Designer.cs b/ChaosBot/Migrations/20200824124830_CustomCommand.Designer.cs index f256454..6bdc93b 100644 --- a/ChaosBot/Migrations/20200824124830_CustomCommand.Designer.cs +++ b/ChaosBot/Migrations/20200824124830_CustomCommand.Designer.cs @@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ChaosBot.Migrations { - [DbContext(typeof(ChaosbotContext))] + [DbContext(typeof(DatabaseContext))] [Migration("20200824124830_CustomCommand")] partial class CustomCommand { diff --git a/ChaosBot/Migrations/ChaosbotContextModelSnapshot.cs b/ChaosBot/Migrations/ChaosbotContextModelSnapshot.cs index 9abe71a..4b2c7a8 100644 --- a/ChaosBot/Migrations/ChaosbotContextModelSnapshot.cs +++ b/ChaosBot/Migrations/ChaosbotContextModelSnapshot.cs @@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace ChaosBot.Migrations { - [DbContext(typeof(ChaosbotContext))] + [DbContext(typeof(DatabaseContext))] partial class ChaosbotContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) diff --git a/ChaosBot/Services/CheckPermissions.cs b/ChaosBot/Services/CheckPermissions.cs index 31f8575..1c8d5c4 100644 --- a/ChaosBot/Services/CheckPermissions.cs +++ b/ChaosBot/Services/CheckPermissions.cs @@ -18,7 +18,7 @@ namespace ChaosBot.Services // Get the possible permissions List commandPermissions; - using (ChaosbotContext dbContext = new ChaosbotContext()) + using (DatabaseContext dbContext = new DatabaseContext()) { IQueryable permissions = dbContext.CommandPermissions; commandPermissions = permissions.Where(p => p.Command.Equals(command)) diff --git a/ChaosBot/WebServer/App/ApiControllers/BaseApiController.cs b/ChaosBot/WebServer/App/ApiControllers/BaseApiController.cs index fe079af..81f7cef 100644 --- a/ChaosBot/WebServer/App/ApiControllers/BaseApiController.cs +++ b/ChaosBot/WebServer/App/ApiControllers/BaseApiController.cs @@ -33,7 +33,7 @@ namespace ChaosBot.WebServer.App.ApiControllers if (!CheckPermissions.GetResult(AccessTokenCache, Request, guildId, out IActionResult result)) return result; - await using ChaosbotContext dbContext = new ChaosbotContext(); + await using DatabaseContext dbContext = new DatabaseContext(); IQueryable query = GetBasicQuery(dbContext); List list = ApplyFilterForCurrentGuild(query, guildId).ToList(); @@ -63,7 +63,7 @@ namespace ChaosBot.WebServer.App.ApiControllers if (!ValidationService.Validate(requestBody, GetValidationRules(), out string errors)) return BadRequest(errors); - await using ChaosbotContext dbContext = new ChaosbotContext(); + await using DatabaseContext dbContext = new DatabaseContext(); T databaseObject = SetDefaultFieldsForUpsert(new T(), guildId); @@ -95,7 +95,7 @@ namespace ChaosBot.WebServer.App.ApiControllers if (!CheckPermissions.GetResult(AccessTokenCache, Request, guildId, out IActionResult result)) return result; - await using ChaosbotContext dbContext = new ChaosbotContext(); + await using DatabaseContext dbContext = new DatabaseContext(); List toDelete = FilterQueryMultipleForDeletion(GetBasicQuery(dbContext), guildId, deleteParameter); toDelete.Add(FilterQueryForDeletion(GetBasicQuery(dbContext), guildId, deleteParameter)); @@ -112,7 +112,7 @@ namespace ChaosBot.WebServer.App.ApiControllers return NoContent(); } - protected abstract DbSet GetBasicQuery(ChaosbotContext context); + protected abstract DbSet GetBasicQuery(DatabaseContext context); protected abstract IQueryable ApplyFilterForCurrentGuild(IQueryable query, ulong guildId); protected abstract List GetIndexFields(); protected abstract Dictionary> GetValidationRules(); diff --git a/ChaosBot/WebServer/App/ApiControllers/CustomCommandController.cs b/ChaosBot/WebServer/App/ApiControllers/CustomCommandController.cs index 9546cad..d364d8c 100644 --- a/ChaosBot/WebServer/App/ApiControllers/CustomCommandController.cs +++ b/ChaosBot/WebServer/App/ApiControllers/CustomCommandController.cs @@ -46,7 +46,7 @@ namespace ChaosBot.WebServer.App.ApiControllers return await Delete(guildId, command); } - protected override DbSet GetBasicQuery(ChaosbotContext context) + protected override DbSet GetBasicQuery(DatabaseContext context) { return context.CustomCommands; }