deleting Raids and Templates is now logged
This commit is contained in:
parent
300ab2370f
commit
de3a6a9f83
4 changed files with 32 additions and 7 deletions
|
@ -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<bool> 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)))
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue