deleting Raids and Templates is now logged

This commit is contained in:
Sarah Faey 2022-12-03 17:13:29 +01:00
parent 300ab2370f
commit de3a6a9f83
4 changed files with 32 additions and 7 deletions

View file

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