diff --git a/Lieb/Data/RaidService.cs b/Lieb/Data/RaidService.cs index 8a2066a..35a9022 100644 --- a/Lieb/Data/RaidService.cs +++ b/Lieb/Data/RaidService.cs @@ -85,7 +85,7 @@ namespace Lieb.Data } } - public async Task DeleteRaid(int raidId) + public async Task DeleteRaid(int raidId, ulong? userId) { using var context = _contextFactory.CreateDbContext(); Raid raid = GetRaid(raidId); @@ -110,6 +110,19 @@ namespace Lieb.Data context.Raids.Remove(raid); await context.SaveChangesAsync(); + if(userId != null) + { + LiebUser user = context.LiebUsers.ToList().FirstOrDefault(u => u.Id == userId, new LiebUser()); + RaidLog logEntry = new RaidLog() + { + LogEntry = $"The Raid \"{raid.Title}\" was deleted by {user.Name}", + Time = DateTimeOffset.UtcNow, + Type = RaidLog.LogType.Raid, + UserId = userId + }; + context.RaidLogs.Add(logEntry); + await context.SaveChangesAsync(); + } } public async Task SignUp(int raidId, ulong liebUserId, int guildWars2AccountId, int plannedRoleId, SignUpType signUpType, ulong signedUpByUserId = 0) @@ -530,7 +543,7 @@ namespace Lieb.Data DateTimeOffset utcNow = DateTimeOffset.UtcNow; foreach(Raid raid in raids.Where(r => r.EndTimeUTC < utcNow.AddYears(-1))) { - await DeleteRaid(raid.RaidId); + await DeleteRaid(raid.RaidId, null); } foreach(Raid raid in raids.Where(r => r.EndTimeUTC < utcNow.AddHours(-1) && (r.DiscordRaidMessages.Count > 0 || r.Reminders.Count > 0))) diff --git a/Lieb/Data/RaidTemplateService.cs b/Lieb/Data/RaidTemplateService.cs index 7e2c7c5..9bb93ba 100644 --- a/Lieb/Data/RaidTemplateService.cs +++ b/Lieb/Data/RaidTemplateService.cs @@ -1,4 +1,5 @@ -using Lieb.Models.GuildWars2.Raid; +using Lieb.Models; +using Lieb.Models.GuildWars2.Raid; using Microsoft.EntityFrameworkCore; namespace Lieb.Data @@ -58,7 +59,7 @@ namespace Lieb.Data } } - public async Task DeleteTemplate(int raidTemplateId) + public async Task DeleteTemplate(int raidTemplateId, ulong userId) { using var context = _contextFactory.CreateDbContext(); RaidTemplate template = GetTemplate(raidTemplateId); @@ -73,6 +74,17 @@ namespace Lieb.Data template.TemplateLogs.Clear(); context.RaidTemplates.Remove(template); await context.SaveChangesAsync(); + + LiebUser user = context.LiebUsers.ToList().FirstOrDefault(u => u.Id == userId, new LiebUser()); + RaidLog logEntry = new RaidLog() + { + LogEntry = $"The Template \"{template.Title}\" was deleted by {user.Name}", + Time = DateTimeOffset.UtcNow, + Type = RaidLog.LogType.RaidTemplate, + UserId = userId + }; + context.RaidLogs.Add(logEntry); + await context.SaveChangesAsync(); } public async Task CreateRaidFromTemplate(int raidTempalteId) diff --git a/Lieb/Pages/Raids/RaidEdit/RaidEdit.razor b/Lieb/Pages/Raids/RaidEdit/RaidEdit.razor index b0c6091..c8cd34c 100644 --- a/Lieb/Pages/Raids/RaidEdit/RaidEdit.razor +++ b/Lieb/Pages/Raids/RaidEdit/RaidEdit.razor @@ -259,7 +259,7 @@ bool confirmed = await JsRuntime.InvokeAsync("confirm", "Are you sure you want to delete the raid?"); if (confirmed) { - await RaidService.DeleteRaid(_raid.RaidId); + await RaidService.DeleteRaid(_raid.RaidId, _user.Id); NavigationManager.NavigateTo("raidoverview"); } } diff --git a/Lieb/Pages/Raids/RaidEdit/RaidTemplateEdit.razor b/Lieb/Pages/Raids/RaidEdit/RaidTemplateEdit.razor index ce3cbe0..b4bd39d 100644 --- a/Lieb/Pages/Raids/RaidEdit/RaidTemplateEdit.razor +++ b/Lieb/Pages/Raids/RaidEdit/RaidTemplateEdit.razor @@ -177,7 +177,7 @@
- + @code { @@ -281,7 +281,7 @@ bool confirmed = await JsRuntime.InvokeAsync("confirm", "Are you sure you want to delete the raid?"); if (confirmed) { - await RaidTemplateService.DeleteTemplate(_template.RaidTemplateId); + await RaidTemplateService.DeleteTemplate(_template.RaidTemplateId, _user.Id); NavigationManager.NavigateTo("raidtemplateoverview"); } }