mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-09 03:52:26 +00:00
Add case generation
This commit is contained in:
parent
bc998b1ba9
commit
1eede416d4
4 changed files with 27 additions and 17 deletions
|
@ -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<IActionResult> 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<IActionResult> 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<IActionResult> 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();
|
|
@ -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;
|
||||
|
|
|
@ -163,14 +163,14 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
@if (Model.User != null && Model.User.IsAdmin)
|
||||
@if (Model.User != null && Model.User.IsModerator)
|
||||
{
|
||||
<div class="ui yellow segment">
|
||||
<h2>Admin Options</h2>
|
||||
<div class="ui green segment">
|
||||
<h2>Moderator Options</h2>
|
||||
|
||||
@if (Model.Slot?.TeamPick ?? false)
|
||||
{
|
||||
<a href="/admin/slot/@Model.Slot.SlotId/removeTeamPick">
|
||||
<a href="/moderation/slot/@Model.Slot.SlotId/removeTeamPick">
|
||||
<div class="ui pink button">
|
||||
<i class="ribbon icon"></i>
|
||||
<span>Remove Team Pick</span>
|
||||
|
@ -179,7 +179,7 @@
|
|||
}
|
||||
else
|
||||
{
|
||||
<a href="/admin/slot/@Model.Slot?.SlotId/teamPick">
|
||||
<a href="/moderation/slot/@Model.Slot?.SlotId/teamPick">
|
||||
<div class="ui pink button">
|
||||
<i class="ribbon icon"></i>
|
||||
<span>Team Pick</span>
|
||||
|
@ -187,7 +187,7 @@
|
|||
</a>
|
||||
}
|
||||
|
||||
<a href="/admin/slot/@Model.Slot?.SlotId/delete">
|
||||
<a href="/moderation/slot/@Model.Slot?.SlotId/delete">
|
||||
<div class="ui red button">
|
||||
<i class="trash icon"></i>
|
||||
<span>Delete</span>
|
||||
|
|
|
@ -44,4 +44,13 @@ public class ModerationCase
|
|||
return database.Slots.FirstOrDefaultAsync(u => u.SlotId == this.AffectedId)!;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static ModerationCase NewTeamPickCase(int caseCreator, int slotId, bool added) => new()
|
||||
{
|
||||
CaseType = added ? CaseType.LevelTeamPickAdded : CaseType.LevelTeamPickRemoved,
|
||||
CaseDescription = "",
|
||||
CaseCreatorId = caseCreator,
|
||||
CaseCreated = DateTime.Now,
|
||||
AffectedId = slotId,
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue