Move DatabaseContext to root
This commit is contained in:
parent
b544275728
commit
ae1a15ad32
@ -17,7 +17,7 @@ namespace ChaosBot.ConfigHelpers
|
|||||||
|
|
||||||
public static T GetValue<T>(string key, ulong guildId, T defaultValue)
|
public static T GetValue<T>(string key, ulong guildId, T defaultValue)
|
||||||
{
|
{
|
||||||
using ChaosbotContext dbContext = new ChaosbotContext();
|
using DatabaseContext dbContext = new DatabaseContext();
|
||||||
Models.Configuration config = dbContext.Configuration
|
Models.Configuration config = dbContext.Configuration
|
||||||
.SingleOrDefault(c => c.DiscordGuildId == guildId && c.Key == key);
|
.SingleOrDefault(c => c.DiscordGuildId == guildId && c.Key == key);
|
||||||
if (config == null || string.IsNullOrEmpty(config.SerializedValue))
|
if (config == null || string.IsNullOrEmpty(config.SerializedValue))
|
||||||
@ -27,7 +27,7 @@ namespace ChaosBot.ConfigHelpers
|
|||||||
|
|
||||||
public static void SetValue<T>(string key, T value, ulong guildId)
|
public static void SetValue<T>(string key, T value, ulong guildId)
|
||||||
{
|
{
|
||||||
using ChaosbotContext dbContext = new ChaosbotContext();
|
using DatabaseContext dbContext = new DatabaseContext();
|
||||||
Models.Configuration cnfSet = new Models.Configuration();
|
Models.Configuration cnfSet = new Models.Configuration();
|
||||||
|
|
||||||
cnfSet.Key = key;
|
cnfSet.Key = key;
|
||||||
@ -41,7 +41,7 @@ namespace ChaosBot.ConfigHelpers
|
|||||||
|
|
||||||
public static void DeleteValue(string key, ulong guildId)
|
public static void DeleteValue(string key, ulong guildId)
|
||||||
{
|
{
|
||||||
using ChaosbotContext dbContext = new ChaosbotContext();
|
using DatabaseContext dbContext = new DatabaseContext();
|
||||||
Models.Configuration config = dbContext.Configuration
|
Models.Configuration config = dbContext.Configuration
|
||||||
.SingleOrDefault(c => c.DiscordGuildId == guildId && c.Key == key);
|
.SingleOrDefault(c => c.DiscordGuildId == guildId && c.Key == key);
|
||||||
if (config == null) return;
|
if (config == null) return;
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
|
using ChaosBot.Models;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace ChaosBot.Models
|
namespace ChaosBot
|
||||||
{
|
{
|
||||||
public class ChaosbotContext : DbContext
|
public class DatabaseContext : DbContext
|
||||||
{
|
{
|
||||||
public DbSet<LodestoneCharacter> LodestoneCharacter { get; set; }
|
public DbSet<LodestoneCharacter> LodestoneCharacter { get; set; }
|
||||||
public DbSet<LodestoneFreeCompany> LodestoneFreeCompany { get; set; }
|
public DbSet<LodestoneFreeCompany> LodestoneFreeCompany { get; set; }
|
||||||
@ -60,7 +60,7 @@ namespace ChaosBot.Discord.Modules.Admin
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using (ChaosbotContext dbContext = new ChaosbotContext())
|
await using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
string parameterString = String.Join("", parameters);
|
string parameterString = String.Join("", parameters);
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ namespace ChaosBot.Discord.Modules.Admin
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using (ChaosbotContext dbContext = new ChaosbotContext())
|
await using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
string parameterString = String.Join("", parameters);
|
string parameterString = String.Join("", parameters);
|
||||||
|
|
||||||
|
|||||||
@ -26,7 +26,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
embed.Title = $"Current Level Statistics";
|
embed.Title = $"Current Level Statistics";
|
||||||
sb.AppendLine();
|
sb.AppendLine();
|
||||||
|
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Experience> ctxUser = dbContext.ExperiencePoints;
|
IQueryable<Experience> ctxUser = dbContext.ExperiencePoints;
|
||||||
IQueryable<Experience> usrXp = ctxUser
|
IQueryable<Experience> usrXp = ctxUser
|
||||||
|
|||||||
@ -165,7 +165,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool linked;
|
bool linked;
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter;
|
IQueryable<LodestoneCharacter> ctxlsChars = dbContext.LodestoneCharacter;
|
||||||
IQueryable<LodestoneCharacter> lsChar = ctxlsChars.Where(p => p.DiscordGuildId.Equals(Context.Guild.Id)).Where(p => p.LodestoneId.Equals(Convert.ToUInt64(character.Character.ID)));
|
IQueryable<LodestoneCharacter> 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))
|
if (character.Character.Bio.Contains(b64))
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
LodestoneCharacter lsChar = new LodestoneCharacter();
|
LodestoneCharacter lsChar = new LodestoneCharacter();
|
||||||
|
|
||||||
|
|||||||
@ -113,7 +113,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Point> points = dbContext.Points;
|
IQueryable<Point> points = dbContext.Points;
|
||||||
cur = points
|
cur = points
|
||||||
@ -135,7 +135,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
ulong cur = 0;
|
ulong cur = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Point> ctxPoints = dbContext.Points;
|
IQueryable<Point> ctxPoints = dbContext.Points;
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
{
|
{
|
||||||
if (admin)
|
if (admin)
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Point> ctxPoints = dbContext.Points;
|
IQueryable<Point> ctxPoints = dbContext.Points;
|
||||||
|
|
||||||
@ -211,7 +211,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Point> ctxPoints = dbContext.Points;
|
IQueryable<Point> ctxPoints = dbContext.Points;
|
||||||
|
|
||||||
@ -276,7 +276,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
Point usrPoint = new Point();
|
Point usrPoint = new Point();
|
||||||
|
|
||||||
|
|||||||
@ -126,7 +126,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
{
|
{
|
||||||
if (admin)
|
if (admin)
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
int cur = 0;
|
int cur = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
||||||
|
|
||||||
@ -224,7 +224,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
||||||
|
|
||||||
@ -258,7 +258,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
{
|
{
|
||||||
if(confirm == "confirm")
|
if(confirm == "confirm")
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
||||||
|
|
||||||
@ -293,7 +293,7 @@ namespace ChaosBot.Discord.Modules.User
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
IQueryable<Raffle> ctxRaffles = dbContext.Raffles;
|
||||||
|
|
||||||
|
|||||||
@ -106,7 +106,7 @@ namespace ChaosBot.Discord.Services
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
Experience newUser = new Experience();
|
Experience newUser = new Experience();
|
||||||
newUser.Amount = 0;
|
newUser.Amount = 0;
|
||||||
@ -131,7 +131,7 @@ namespace ChaosBot.Discord.Services
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Experience> ctxUser = dbContext.ExperiencePoints;
|
IQueryable<Experience> ctxUser = dbContext.ExperiencePoints;
|
||||||
IQueryable<Experience> usrXp = ctxUser
|
IQueryable<Experience> usrXp = ctxUser
|
||||||
|
|||||||
@ -15,7 +15,7 @@ namespace ChaosBot.Discord.Services
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using ChaosbotContext dbContext = new ChaosbotContext();
|
await using DatabaseContext dbContext = new DatabaseContext();
|
||||||
string command = context.Message.Content.Substring(argPos);
|
string command = context.Message.Content.Substring(argPos);
|
||||||
|
|
||||||
IQueryable<CustomCommand> customCommandQuery = dbContext.CustomCommands;
|
IQueryable<CustomCommand> customCommandQuery = dbContext.CustomCommands;
|
||||||
|
|||||||
@ -18,7 +18,7 @@ namespace ChaosBot.Discord.Services
|
|||||||
{
|
{
|
||||||
if (!CheckModuleEnabled.GetResult(context, "Experience")) return;
|
if (!CheckModuleEnabled.GetResult(context, "Experience")) return;
|
||||||
|
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<Experience> ctxUser = dbContext.ExperiencePoints;
|
IQueryable<Experience> ctxUser = dbContext.ExperiencePoints;
|
||||||
IQueryable<Experience> usrXp = ctxUser
|
IQueryable<Experience> usrXp = ctxUser
|
||||||
|
|||||||
@ -17,7 +17,7 @@ namespace ChaosBot.Discord.Services
|
|||||||
if (!(optionalUser.Value is IGuildUser user)) return;
|
if (!(optionalUser.Value is IGuildUser user)) return;
|
||||||
if (!(socketMessageChannel is SocketGuildChannel channel)) return;
|
if (!(socketMessageChannel is SocketGuildChannel channel)) return;
|
||||||
|
|
||||||
await using ChaosbotContext dbContext = new ChaosbotContext();
|
await using DatabaseContext dbContext = new DatabaseContext();
|
||||||
|
|
||||||
IQueryable<RoleReaction> roleReactionsQueryable = dbContext.RoleReactions;
|
IQueryable<RoleReaction> roleReactionsQueryable = dbContext.RoleReactions;
|
||||||
List<RoleReaction> roleReactions = roleReactionsQueryable
|
List<RoleReaction> roleReactions = roleReactionsQueryable
|
||||||
@ -47,7 +47,7 @@ namespace ChaosBot.Discord.Services
|
|||||||
if (!(optionalUser.Value is IGuildUser user)) return;
|
if (!(optionalUser.Value is IGuildUser user)) return;
|
||||||
if (!(socketMessageChannel is SocketGuildChannel channel)) return;
|
if (!(socketMessageChannel is SocketGuildChannel channel)) return;
|
||||||
|
|
||||||
await using ChaosbotContext dbContext = new ChaosbotContext();
|
await using DatabaseContext dbContext = new DatabaseContext();
|
||||||
|
|
||||||
IQueryable<RoleReaction> roleReactionsQueryable = dbContext.RoleReactions;
|
IQueryable<RoleReaction> roleReactionsQueryable = dbContext.RoleReactions;
|
||||||
List<RoleReaction> roleReactions = roleReactionsQueryable
|
List<RoleReaction> roleReactions = roleReactionsQueryable
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200804195804_LodestoneCharacter")]
|
[Migration("20200804195804_LodestoneCharacter")]
|
||||||
partial class LodestoneCharacter
|
partial class LodestoneCharacter
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200804202834_LodestoneFreeCompany")]
|
[Migration("20200804202834_LodestoneFreeCompany")]
|
||||||
partial class LodestoneFreeCompany
|
partial class LodestoneFreeCompany
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200804203214_Points")]
|
[Migration("20200804203214_Points")]
|
||||||
partial class Points
|
partial class Points
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200804204404_Raffles")]
|
[Migration("20200804204404_Raffles")]
|
||||||
partial class Raffles
|
partial class Raffles
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200804204734_CommandPermissions")]
|
[Migration("20200804204734_CommandPermissions")]
|
||||||
partial class CommandPermissions
|
partial class CommandPermissions
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200804205955_Configuration")]
|
[Migration("20200804205955_Configuration")]
|
||||||
partial class Configuration
|
partial class Configuration
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200804213001_ExperiencePoints")]
|
[Migration("20200804213001_ExperiencePoints")]
|
||||||
partial class ExperiencePoints
|
partial class ExperiencePoints
|
||||||
{
|
{
|
||||||
|
|||||||
@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200819203430_RoleReaction")]
|
[Migration("20200819203430_RoleReaction")]
|
||||||
partial class RoleReaction
|
partial class RoleReaction
|
||||||
{
|
{
|
||||||
|
|||||||
@ -8,7 +8,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
[Migration("20200824124830_CustomCommand")]
|
[Migration("20200824124830_CustomCommand")]
|
||||||
partial class CustomCommand
|
partial class CustomCommand
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
|
|
||||||
namespace ChaosBot.Migrations
|
namespace ChaosBot.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(ChaosbotContext))]
|
[DbContext(typeof(DatabaseContext))]
|
||||||
partial class ChaosbotContextModelSnapshot : ModelSnapshot
|
partial class ChaosbotContextModelSnapshot : ModelSnapshot
|
||||||
{
|
{
|
||||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||||
|
|||||||
@ -18,7 +18,7 @@ namespace ChaosBot.Services
|
|||||||
|
|
||||||
// Get the possible permissions
|
// Get the possible permissions
|
||||||
List<CommandPermission> commandPermissions;
|
List<CommandPermission> commandPermissions;
|
||||||
using (ChaosbotContext dbContext = new ChaosbotContext())
|
using (DatabaseContext dbContext = new DatabaseContext())
|
||||||
{
|
{
|
||||||
IQueryable<CommandPermission> permissions = dbContext.CommandPermissions;
|
IQueryable<CommandPermission> permissions = dbContext.CommandPermissions;
|
||||||
commandPermissions = permissions.Where(p => p.Command.Equals(command))
|
commandPermissions = permissions.Where(p => p.Command.Equals(command))
|
||||||
|
|||||||
@ -33,7 +33,7 @@ namespace ChaosBot.WebServer.App.ApiControllers
|
|||||||
if (!CheckPermissions.GetResult(AccessTokenCache, Request, guildId, out IActionResult result))
|
if (!CheckPermissions.GetResult(AccessTokenCache, Request, guildId, out IActionResult result))
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
await using ChaosbotContext dbContext = new ChaosbotContext();
|
await using DatabaseContext dbContext = new DatabaseContext();
|
||||||
|
|
||||||
IQueryable<T> query = GetBasicQuery(dbContext);
|
IQueryable<T> query = GetBasicQuery(dbContext);
|
||||||
List<T> list = ApplyFilterForCurrentGuild(query, guildId).ToList();
|
List<T> list = ApplyFilterForCurrentGuild(query, guildId).ToList();
|
||||||
@ -63,7 +63,7 @@ namespace ChaosBot.WebServer.App.ApiControllers
|
|||||||
if (!ValidationService.Validate(requestBody, GetValidationRules(), out string errors))
|
if (!ValidationService.Validate(requestBody, GetValidationRules(), out string errors))
|
||||||
return BadRequest(errors);
|
return BadRequest(errors);
|
||||||
|
|
||||||
await using ChaosbotContext dbContext = new ChaosbotContext();
|
await using DatabaseContext dbContext = new DatabaseContext();
|
||||||
|
|
||||||
T databaseObject = SetDefaultFieldsForUpsert(new T(), guildId);
|
T databaseObject = SetDefaultFieldsForUpsert(new T(), guildId);
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ namespace ChaosBot.WebServer.App.ApiControllers
|
|||||||
if (!CheckPermissions.GetResult(AccessTokenCache, Request, guildId, out IActionResult result))
|
if (!CheckPermissions.GetResult(AccessTokenCache, Request, guildId, out IActionResult result))
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
await using ChaosbotContext dbContext = new ChaosbotContext();
|
await using DatabaseContext dbContext = new DatabaseContext();
|
||||||
|
|
||||||
List<T> toDelete = FilterQueryMultipleForDeletion(GetBasicQuery(dbContext), guildId, deleteParameter);
|
List<T> toDelete = FilterQueryMultipleForDeletion(GetBasicQuery(dbContext), guildId, deleteParameter);
|
||||||
toDelete.Add(FilterQueryForDeletion(GetBasicQuery(dbContext), guildId, deleteParameter));
|
toDelete.Add(FilterQueryForDeletion(GetBasicQuery(dbContext), guildId, deleteParameter));
|
||||||
@ -112,7 +112,7 @@ namespace ChaosBot.WebServer.App.ApiControllers
|
|||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract DbSet<T> GetBasicQuery(ChaosbotContext context);
|
protected abstract DbSet<T> GetBasicQuery(DatabaseContext context);
|
||||||
protected abstract IQueryable<T> ApplyFilterForCurrentGuild(IQueryable<T> query, ulong guildId);
|
protected abstract IQueryable<T> ApplyFilterForCurrentGuild(IQueryable<T> query, ulong guildId);
|
||||||
protected abstract List<string> GetIndexFields();
|
protected abstract List<string> GetIndexFields();
|
||||||
protected abstract Dictionary<string, List<string>> GetValidationRules();
|
protected abstract Dictionary<string, List<string>> GetValidationRules();
|
||||||
|
|||||||
@ -46,7 +46,7 @@ namespace ChaosBot.WebServer.App.ApiControllers
|
|||||||
return await Delete(guildId, command);
|
return await Delete(guildId, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override DbSet<CustomCommand> GetBasicQuery(ChaosbotContext context)
|
protected override DbSet<CustomCommand> GetBasicQuery(DatabaseContext context)
|
||||||
{
|
{
|
||||||
return context.CustomCommands;
|
return context.CustomCommands;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user