mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-28 16:08:38 +00:00
Properly organize mod panel related pages
This commit is contained in:
parent
e962c2dee4
commit
5b1342c29d
10 changed files with 10 additions and 13 deletions
|
@ -0,0 +1,61 @@
|
|||
using LBPUnion.ProjectLighthouse.Administration;
|
||||
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
|
||||
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages.Moderation;
|
||||
|
||||
public class NewCasePage : BaseLayout
|
||||
{
|
||||
public NewCasePage(Database database) : base(database)
|
||||
{}
|
||||
|
||||
public CaseType Type { get; set; }
|
||||
public int AffectedId { get; set; }
|
||||
|
||||
public IActionResult OnGet([FromQuery] CaseType? type, [FromQuery] int? affectedId)
|
||||
{
|
||||
User? user = this.Database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsModerator) return this.Redirect("/login");
|
||||
|
||||
if (type == null) return this.BadRequest();
|
||||
if (affectedId == null) return this.BadRequest();
|
||||
|
||||
this.Type = (CaseType)type;
|
||||
this.AffectedId = (int)affectedId;
|
||||
|
||||
return this.Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPost(CaseType? type, string? reason, string? modNotes, DateTime expires, int? affectedId)
|
||||
{
|
||||
User? user = this.Database.UserFromWebRequest(this.Request);
|
||||
if (user == null || !user.IsModerator) return this.Redirect("/login");
|
||||
|
||||
if (type == null) return this.BadRequest();
|
||||
if (affectedId == null) return this.BadRequest();
|
||||
|
||||
reason ??= string.Empty;
|
||||
modNotes ??= string.Empty;
|
||||
|
||||
// this is fucking ugly
|
||||
// if id is invalid then return bad request
|
||||
if (!(await ((CaseType)type).IsIdValid((int)affectedId, this.Database))) return this.BadRequest();
|
||||
|
||||
ModerationCase @case = new()
|
||||
{
|
||||
Type = (CaseType)type,
|
||||
Reason = reason,
|
||||
ModeratorNotes = modNotes,
|
||||
ExpiresAt = expires,
|
||||
CreatedAt = DateTime.Now,
|
||||
CreatorId = user.UserId,
|
||||
AffectedId = (int)affectedId,
|
||||
};
|
||||
|
||||
this.Database.Cases.Add(@case);
|
||||
await this.Database.SaveChangesAsync();
|
||||
|
||||
return this.Redirect("/moderation/cases/0");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue