fixed errors while logging raids

SQlite is now also used in production
This commit is contained in:
Sarah Faey 2022-11-24 17:56:06 +01:00
parent 7d6bc48dba
commit fc5e75cc9d
5 changed files with 12 additions and 20 deletions

View file

@ -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);
}
}

View file

@ -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();
}
}

View file

@ -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,

View file

@ -9,14 +9,8 @@ var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
#if DEBUG
builder.Services.AddDbContextFactory<LiebContext>(opt =>
//opt.UseSqlServer(builder.Configuration.GetConnectionString("LiebContext")).EnableSensitiveDataLogging(), ServiceLifetime.Transient);
opt.UseSqlite(builder.Configuration.GetConnectionString("LiebContext")));
#else
builder.Services.AddDbContextFactory<LiebContext>(opt =>
opt.UseMySql(builder.Configuration.GetConnectionString("LiebContext"), ServerVersion.AutoDetect(builder.Configuration.GetConnectionString("LiebContext"))), ServiceLifetime.Transient);
#endif
builder.Services.AddDatabaseDeveloperPageExceptionFilter();

View file

@ -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"
}
}
}