diff --git a/ProjectLighthouse.Servers.Website/Pages/Moderation/NewCasePage.cshtml b/ProjectLighthouse.Servers.Website/Pages/Moderation/NewCasePage.cshtml index cfcdb438..7084ae00 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Moderation/NewCasePage.cshtml +++ b/ProjectLighthouse.Servers.Website/Pages/Moderation/NewCasePage.cshtml @@ -2,6 +2,7 @@ @using LBPUnion.ProjectLighthouse.Localization.StringLists @using LBPUnion.ProjectLighthouse.Servers.Website.Extensions @using LBPUnion.ProjectLighthouse.Types.Entities.Moderation +@using LBPUnion.ProjectLighthouse.Types.Moderation.Cases @model LBPUnion.ProjectLighthouse.Servers.Website.Pages.Moderation.NewCasePage @{ @@ -27,9 +28,18 @@
Case Type: @Model.Type.ToString()
-
- Affected User: @Model.AffectedUser!.Username (id: @Model.AffectedId) -
+ @if (Model.Type.AffectsUser()) + { +
+ Affected User: @Model.AffectedUser!.Username (id: @Model.AffectedId) +
+ } + else if (Model.Type.AffectsLevel()) + { +
+ Affected Level: @Model.AffectedSlot!.Name (id: @Model.AffectedId) +
+ }
@@ -50,36 +60,39 @@
-
-
- Moderation history for user @Model.AffectedUser!.Username -
- @if (Model.AffectedHistory.Count != 0) - { - @foreach (ModerationCaseEntity moderationCase in Model.AffectedHistory) + @if (Model.Type.AffectsUser()) + { +
+
+ Moderation history for user @Model.AffectedUser!.Username +
+ @if (Model.AffectedHistory.Count != 0) + { + @foreach (ModerationCaseEntity moderationCase in Model.AffectedHistory) + { +
+ +
+ @moderationCase.Type.ToString() by @moderationCase.CreatorUsername + on @TimeZoneInfo.ConvertTime(moderationCase.CreatedAt, timeZoneInfo).ToString("M/d/yyyy @ h:mm tt") + with reason @(!string.IsNullOrWhiteSpace(moderationCase.Reason) ? moderationCase.Reason : "No reason provided") +
+
+ } + } + else {
- +
- @moderationCase.Type.ToString() by @moderationCase.CreatorUsername - on @TimeZoneInfo.ConvertTime(moderationCase.CreatedAt, timeZoneInfo).ToString("M/d/yyyy @ h:mm tt") - with reason @(!string.IsNullOrWhiteSpace(moderationCase.Reason) ? moderationCase.Reason : "No reason provided") + No moderation history found for user @Model.AffectedUser!.Username
} - } - else - { -
- -
- No moderation history found for user @Model.AffectedUser!.Username -
-
- } -
-
-
+
+
+
+ }
diff --git a/ProjectLighthouse.Servers.Website/Pages/Moderation/NewCasePage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/Moderation/NewCasePage.cshtml.cs index 19f3387c..19782b4c 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Moderation/NewCasePage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/Moderation/NewCasePage.cshtml.cs @@ -1,6 +1,7 @@ using LBPUnion.ProjectLighthouse.Database; using LBPUnion.ProjectLighthouse.Localization.StringLists; using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts; +using LBPUnion.ProjectLighthouse.Types.Entities.Level; using LBPUnion.ProjectLighthouse.Types.Entities.Moderation; using LBPUnion.ProjectLighthouse.Types.Entities.Profile; using LBPUnion.ProjectLighthouse.Types.Moderation.Cases; @@ -18,6 +19,7 @@ public class NewCasePage : BaseLayout public int AffectedId { get; set; } public UserEntity? AffectedUser { get; set; } + public SlotEntity? AffectedSlot { get; set; } public List AffectedHistory { get; set; } = new(); public string? Error { get; private set; } @@ -33,9 +35,18 @@ public class NewCasePage : BaseLayout this.Type = type.Value; this.AffectedId = affectedId.Value; - - this.AffectedUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == this.AffectedId); - if (this.AffectedUser == null) return this.BadRequest(); + + if (this.Type.AffectsUser()) + { + this.AffectedUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == this.AffectedId); + if (this.AffectedUser == null) return this.BadRequest(); + } + else if (this.Type.AffectsLevel()) + { + this.AffectedSlot = await this.Database.Slots.FirstOrDefaultAsync(s => s.SlotId == this.AffectedId); + if (this.AffectedSlot == null) return this.BadRequest(); + } + else return this.BadRequest(); this.AffectedHistory = await this.Database.Cases.Where(c => c.AffectedId == this.AffectedId) .OrderByDescending(c => c.CreatedAt) @@ -58,15 +69,27 @@ public class NewCasePage : BaseLayout // if id is invalid then return bad request if (!await type.Value.IsIdValid((int)affectedId, this.Database)) return this.BadRequest(); - UserEntity? affectedUser = - await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == affectedId.Value); - - if (affectedUser == null) return this.NotFound(); - - if (affectedUser.IsModerator) + if (type.Value.AffectsUser()) { - this.Error = this.Translate(ErrorStrings.ActionNoPermission); - return this.Page(); + UserEntity? affectedUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == affectedId.Value); + if (affectedUser == null) return this.NotFound(); + + if (affectedUser.IsModerator) + { + this.Error = this.Translate(ErrorStrings.ActionNoPermission); + + this.Type = type.Value; + + this.AffectedId = affectedId.Value; + + this.AffectedUser = affectedUser; + + this.AffectedHistory = await this.Database.Cases.Where(c => c.AffectedId == this.AffectedId) + .OrderByDescending(c => c.CreatedAt) + .ToListAsync(); + + return this.Page(); + } } ModerationCaseEntity @case = new()