Add debug option to create new cases in the database

Used until we have a system to create cases when moderation actions are taken
This commit is contained in:
jvyden 2022-07-26 23:32:44 -04:00
commit 13f935ffde
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
6 changed files with 104 additions and 31 deletions

View file

@ -1,8 +1,10 @@
using LBPUnion.ProjectLighthouse.Administration;
using LBPUnion.ProjectLighthouse.Configuration;
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages;
@ -11,37 +13,28 @@ public class CasePage : BaseLayout
public CasePage(Database database) : base(database)
{}
public List<ModerationCase> Cases = new();
public async Task<IActionResult> OnGet(int pageNumber)
public List<ModerationCase> Cases;
public int CaseCount;
public int PageAmount;
public int PageNumber;
public string SearchValue = "";
public async Task<IActionResult> OnGet([FromRoute] int pageNumber, [FromQuery] string? name)
{
User? user = this.Database.UserFromWebRequest(this.Request);
if (user == null) return this.NotFound();
if (!user.IsModerator) return this.NotFound();
this.Cases.Add(new ModerationCase
{
CaseId = 1,
CaseCreated = DateTime.Now,
CaseExpires = new DateTime(2011, 11, 17),
CaseCreatorId = user.UserId,
CaseCreator = user,
CaseDescription = "Being a dumbass",
CaseType = CaseType.UserBan,
AffectedId = user.UserId,
});
this.Cases.Add(new ModerationCase
{
CaseId = 2,
CaseCreated = DateTime.Now,
CaseExpires = new DateTime(2023, 11, 17),
CaseCreatorId = user.UserId,
CaseCreator = user,
CaseDescription = "Being too cool",
CaseType = CaseType.UserSilence,
AffectedId = user.UserId,
});
if (string.IsNullOrWhiteSpace(name)) name = "";
this.SearchValue = name.Replace(" ", string.Empty);
this.Cases = await this.Database.Cases.ToListAsync();
this.CaseCount = await this.Database.Cases.CountAsync(c => c.CaseDescription.Contains(this.SearchValue));
this.PageNumber = pageNumber;
this.PageAmount = Math.Max(1, (int)Math.Ceiling((double)this.CaseCount / ServerStatics.PageSize));
return this.Page();
}