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();
|
using var context = _contextFactory.CreateDbContext();
|
||||||
Raid raid = GetRaid(raidId);
|
Raid raid = GetRaid(raidId);
|
||||||
|
@ -110,6 +110,19 @@ namespace Lieb.Data
|
||||||
context.Raids.Remove(raid);
|
context.Raids.Remove(raid);
|
||||||
await context.SaveChangesAsync();
|
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)
|
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;
|
DateTimeOffset utcNow = DateTimeOffset.UtcNow;
|
||||||
foreach(Raid raid in raids.Where(r => r.EndTimeUTC < utcNow.AddYears(-1)))
|
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)
|
foreach(Raid raid in raids.Where(r => r.EndTimeUTC < utcNow.AddHours(-1)
|
||||||
&& (r.DiscordRaidMessages.Count > 0 || r.Reminders.Count > 0)))
|
&& (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;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Lieb.Data
|
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();
|
using var context = _contextFactory.CreateDbContext();
|
||||||
RaidTemplate template = GetTemplate(raidTemplateId);
|
RaidTemplate template = GetTemplate(raidTemplateId);
|
||||||
|
@ -73,6 +74,17 @@ namespace Lieb.Data
|
||||||
template.TemplateLogs.Clear();
|
template.TemplateLogs.Clear();
|
||||||
context.RaidTemplates.Remove(template);
|
context.RaidTemplates.Remove(template);
|
||||||
await context.SaveChangesAsync();
|
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)
|
public async Task CreateRaidFromTemplate(int raidTempalteId)
|
||||||
|
|
|
@ -259,7 +259,7 @@
|
||||||
bool confirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Are you sure you want to delete the raid?");
|
bool confirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Are you sure you want to delete the raid?");
|
||||||
if (confirmed)
|
if (confirmed)
|
||||||
{
|
{
|
||||||
await RaidService.DeleteRaid(_raid.RaidId);
|
await RaidService.DeleteRaid(_raid.RaidId, _user.Id);
|
||||||
NavigationManager.NavigateTo("raidoverview");
|
NavigationManager.NavigateTo("raidoverview");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,7 +177,7 @@
|
||||||
|
|
||||||
</EditForm>
|
</EditForm>
|
||||||
<br/>
|
<br/>
|
||||||
<button type=button @onclick="() => DeleteRaidClicked()">Delete Raid</button>
|
<button type=button @onclick="() => DeleteRaidClicked()">Delete Template</button>
|
||||||
</AuthorizeView>
|
</AuthorizeView>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
@ -281,7 +281,7 @@
|
||||||
bool confirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Are you sure you want to delete the raid?");
|
bool confirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Are you sure you want to delete the raid?");
|
||||||
if (confirmed)
|
if (confirmed)
|
||||||
{
|
{
|
||||||
await RaidTemplateService.DeleteTemplate(_template.RaidTemplateId);
|
await RaidTemplateService.DeleteTemplate(_template.RaidTemplateId, _user.Id);
|
||||||
NavigationManager.NavigateTo("raidtemplateoverview");
|
NavigationManager.NavigateTo("raidtemplateoverview");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue