From 1eede416d419beac43f1ad76fa71d8c4d854eadd Mon Sep 17 00:00:00 2001 From: jvyden Date: Wed, 27 Jul 2022 17:19:49 -0400 Subject: [PATCH] Add case generation --- ...troller.cs => ModerationSlotController.cs} | 19 +++++++++---------- .../Pages/CasePage.cshtml.cs | 4 +++- .../Pages/SlotPage.cshtml | 12 ++++++------ .../Administration/ModerationCase.cs | 9 +++++++++ 4 files changed, 27 insertions(+), 17 deletions(-) rename ProjectLighthouse.Servers.Website/Controllers/Admin/{AdminSlotController.cs => ModerationSlotController.cs} (72%) diff --git a/ProjectLighthouse.Servers.Website/Controllers/Admin/AdminSlotController.cs b/ProjectLighthouse.Servers.Website/Controllers/Admin/ModerationSlotController.cs similarity index 72% rename from ProjectLighthouse.Servers.Website/Controllers/Admin/AdminSlotController.cs rename to ProjectLighthouse.Servers.Website/Controllers/Admin/ModerationSlotController.cs index 0ef40305..14eb49d2 100644 --- a/ProjectLighthouse.Servers.Website/Controllers/Admin/AdminSlotController.cs +++ b/ProjectLighthouse.Servers.Website/Controllers/Admin/ModerationSlotController.cs @@ -1,4 +1,5 @@ #nullable enable +using LBPUnion.ProjectLighthouse.Administration; using LBPUnion.ProjectLighthouse.Levels; using LBPUnion.ProjectLighthouse.PlayerData.Profiles; using LBPUnion.ProjectLighthouse.Types; @@ -8,12 +9,12 @@ using Microsoft.EntityFrameworkCore; namespace LBPUnion.ProjectLighthouse.Servers.Website.Controllers.Admin; [ApiController] -[Route("admin/slot/{id:int}")] -public class AdminSlotController : ControllerBase +[Route("moderation/slot/{id:int}")] +public class ModerationSlotController : ControllerBase { private readonly Database database; - public AdminSlotController(Database database) + public ModerationSlotController(Database database) { this.database = database; } @@ -22,15 +23,14 @@ public class AdminSlotController : ControllerBase public async Task TeamPick([FromRoute] int id) { User? user = this.database.UserFromWebRequest(this.Request); - if (user == null || !user.IsAdmin) return this.StatusCode(403, ""); + if (user == null || !user.IsModerator) return this.StatusCode(403, ""); Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id); if (slot == null) return this.NotFound(); - slot.TeamPick = true; + this.database.Cases.Add(ModerationCase.NewTeamPickCase(user.UserId, slot.SlotId, true)); await this.database.SaveChangesAsync(); - return this.Ok(); } @@ -38,15 +38,14 @@ public class AdminSlotController : ControllerBase public async Task RemoveTeamPick([FromRoute] int id) { User? user = this.database.UserFromWebRequest(this.Request); - if (user == null || !user.IsAdmin) return this.StatusCode(403, ""); + if (user == null || !user.IsModerator) return this.StatusCode(403, ""); Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id); if (slot == null) return this.NotFound(); - slot.TeamPick = false; + this.database.Cases.Add(ModerationCase.NewTeamPickCase(user.UserId, slot.SlotId, false)); await this.database.SaveChangesAsync(); - return this.Ok(); } @@ -54,7 +53,7 @@ public class AdminSlotController : ControllerBase public async Task DeleteLevel([FromRoute] int id) { User? user = this.database.UserFromWebRequest(this.Request); - if (user == null || !user.IsAdmin) return this.StatusCode(403, ""); + if (user == null || !user.IsModerator) return this.StatusCode(403, ""); Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id); if (slot == null) return this.Ok(); diff --git a/ProjectLighthouse.Servers.Website/Pages/CasePage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/CasePage.cshtml.cs index 5d2dc9ec..2477947d 100644 --- a/ProjectLighthouse.Servers.Website/Pages/CasePage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/CasePage.cshtml.cs @@ -30,7 +30,9 @@ public class CasePage : BaseLayout this.SearchValue = name.Replace(" ", string.Empty); - this.Cases = await this.Database.Cases.ToListAsync(); + this.Cases = await this.Database.Cases + .OrderByDescending(c => c.CaseId) + .ToListAsync(); this.CaseCount = await this.Database.Cases.CountAsync(c => c.CaseDescription.Contains(this.SearchValue)); this.PageNumber = pageNumber; diff --git a/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml b/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml index 55313d80..68123f54 100644 --- a/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml +++ b/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml @@ -163,14 +163,14 @@ -@if (Model.User != null && Model.User.IsAdmin) +@if (Model.User != null && Model.User.IsModerator) { -