From fc5e75cc9d3fa735aa00a852c25d4cf817fcf078 Mon Sep 17 00:00:00 2001 From: Sarah Faey Date: Thu, 24 Nov 2022 17:56:06 +0100 Subject: [PATCH] fixed errors while logging raids SQlite is now also used in production --- Lieb/Data/RaidService.cs | 11 ++++------- Lieb/Data/RaidTemplateService.cs | 7 +++---- Lieb/Models/GuildWars2/Raid/RaidLog.cs | 2 ++ Lieb/Program.cs | 6 ------ Lieb/appsettings.json | 6 +++--- 5 files changed, 12 insertions(+), 20 deletions(-) diff --git a/Lieb/Data/RaidService.cs b/Lieb/Data/RaidService.cs index 1ab31c0..1cd45cc 100644 --- a/Lieb/Data/RaidService.cs +++ b/Lieb/Data/RaidService.cs @@ -58,9 +58,6 @@ namespace Lieb.Data if (raid.RaidId == 0) { context.Raids.Add(raid); - RaidLog log = RaidLog.CreateRaidLog(changedBy, raid); - await context.RaidLogs.AddAsync(log); - await context.SaveChangesAsync(); } else { @@ -79,11 +76,11 @@ namespace Lieb.Data } context.RaidRoles.RemoveRange(raid.Roles.Where(r => !r.IsRandomSignUpRole)); } - - RaidLog log = RaidLog.CreateRaidLog(changedBy, raid); - await context.RaidLogs.AddAsync(log); - await context.SaveChangesAsync(); } + await context.SaveChangesAsync(); + RaidLog log = RaidLog.CreateRaidLog(changedBy, raid); + await context.RaidLogs.AddAsync(log); + await context.SaveChangesAsync(); await _discordService.PostRaidMessage(raid.RaidId); } } diff --git a/Lieb/Data/RaidTemplateService.cs b/Lieb/Data/RaidTemplateService.cs index 59e93b3..9bed87c 100644 --- a/Lieb/Data/RaidTemplateService.cs +++ b/Lieb/Data/RaidTemplateService.cs @@ -39,8 +39,6 @@ namespace Lieb.Data if (template.RaidTemplateId == 0) { context.RaidTemplates.Add(template); - RaidLog log = RaidLog.CreateRaidTemplateLog(changedBy, template); - await context.RaidLogs.AddAsync(log); } else { @@ -48,10 +46,11 @@ namespace Lieb.Data context.RaidRoles.RemoveRange(rolesToDelete); context.RaidReminders.RemoveRange(remindersToDelete); context.DiscordRaidMessages.RemoveRange(messagesToDelete); - RaidLog log = RaidLog.CreateRaidTemplateLog(changedBy, template); - await context.RaidLogs.AddAsync(log); } await context.SaveChangesAsync(); + RaidLog log = RaidLog.CreateRaidTemplateLog(changedBy, template); + await context.RaidLogs.AddAsync(log); + await context.SaveChangesAsync(); } } diff --git a/Lieb/Models/GuildWars2/Raid/RaidLog.cs b/Lieb/Models/GuildWars2/Raid/RaidLog.cs index 8233e0e..0965ff1 100644 --- a/Lieb/Models/GuildWars2/Raid/RaidLog.cs +++ b/Lieb/Models/GuildWars2/Raid/RaidLog.cs @@ -35,6 +35,7 @@ namespace Lieb.Models.GuildWars2.Raid public static RaidLog CreateRaidLog(ulong userId, Raid raid) { raid.RaidLogs.Clear(); + raid.Reminders.Clear(); return new RaidLog() { Type = LogType.Raid, @@ -61,6 +62,7 @@ namespace Lieb.Models.GuildWars2.Raid public static RaidLog CreateRaidTemplateLog(ulong userId, RaidTemplate template) { template.TemplateLogs.Clear(); + template.Reminders.Clear(); return new RaidLog() { Type = LogType.RaidTemplate, diff --git a/Lieb/Program.cs b/Lieb/Program.cs index fa852d3..e973b03 100644 --- a/Lieb/Program.cs +++ b/Lieb/Program.cs @@ -9,14 +9,8 @@ var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorPages(); -#if DEBUG builder.Services.AddDbContextFactory(opt => - //opt.UseSqlServer(builder.Configuration.GetConnectionString("LiebContext")).EnableSensitiveDataLogging(), ServiceLifetime.Transient); opt.UseSqlite(builder.Configuration.GetConnectionString("LiebContext"))); -#else -builder.Services.AddDbContextFactory(opt => - opt.UseMySql(builder.Configuration.GetConnectionString("LiebContext"), ServerVersion.AutoDetect(builder.Configuration.GetConnectionString("LiebContext"))), ServiceLifetime.Transient); -#endif builder.Services.AddDatabaseDeveloperPageExceptionFilter(); diff --git a/Lieb/appsettings.json b/Lieb/appsettings.json index e4c0162..b034e00 100644 --- a/Lieb/appsettings.json +++ b/Lieb/appsettings.json @@ -10,9 +10,9 @@ }, "AllowedHosts": "*", "ConnectionStrings": { - "LiebContext": "Server=liebdb;Database=LiebContext;Uid=root;Pwd=my-secret-pw;" + "LiebContext": "Data Source=/database/mydb.sqlite;" }, "HttpClients": { - "DiscordBot": "discord-bot" + "DiscordBot": "lieb-bot" } -} \ No newline at end of file +}