mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-06 10:42:28 +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
|
#nullable enable
|
||||||
|
using LBPUnion.ProjectLighthouse.Administration;
|
||||||
using LBPUnion.ProjectLighthouse.Levels;
|
using LBPUnion.ProjectLighthouse.Levels;
|
||||||
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
|
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
|
||||||
using LBPUnion.ProjectLighthouse.Types;
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
|
@ -8,12 +9,12 @@ using Microsoft.EntityFrameworkCore;
|
||||||
namespace LBPUnion.ProjectLighthouse.Servers.Website.Controllers.Admin;
|
namespace LBPUnion.ProjectLighthouse.Servers.Website.Controllers.Admin;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("admin/slot/{id:int}")]
|
[Route("moderation/slot/{id:int}")]
|
||||||
public class AdminSlotController : ControllerBase
|
public class ModerationSlotController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly Database database;
|
private readonly Database database;
|
||||||
|
|
||||||
public AdminSlotController(Database database)
|
public ModerationSlotController(Database database)
|
||||||
{
|
{
|
||||||
this.database = database;
|
this.database = database;
|
||||||
}
|
}
|
||||||
|
@ -22,15 +23,14 @@ public class AdminSlotController : ControllerBase
|
||||||
public async Task<IActionResult> TeamPick([FromRoute] int id)
|
public async Task<IActionResult> TeamPick([FromRoute] int id)
|
||||||
{
|
{
|
||||||
User? user = this.database.UserFromWebRequest(this.Request);
|
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);
|
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id);
|
||||||
if (slot == null) return this.NotFound();
|
if (slot == null) return this.NotFound();
|
||||||
|
|
||||||
slot.TeamPick = true;
|
slot.TeamPick = true;
|
||||||
|
this.database.Cases.Add(ModerationCase.NewTeamPickCase(user.UserId, slot.SlotId, true));
|
||||||
|
|
||||||
await this.database.SaveChangesAsync();
|
await this.database.SaveChangesAsync();
|
||||||
|
|
||||||
return this.Ok();
|
return this.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,15 +38,14 @@ public class AdminSlotController : ControllerBase
|
||||||
public async Task<IActionResult> RemoveTeamPick([FromRoute] int id)
|
public async Task<IActionResult> RemoveTeamPick([FromRoute] int id)
|
||||||
{
|
{
|
||||||
User? user = this.database.UserFromWebRequest(this.Request);
|
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);
|
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id);
|
||||||
if (slot == null) return this.NotFound();
|
if (slot == null) return this.NotFound();
|
||||||
|
|
||||||
slot.TeamPick = false;
|
slot.TeamPick = false;
|
||||||
|
this.database.Cases.Add(ModerationCase.NewTeamPickCase(user.UserId, slot.SlotId, false));
|
||||||
|
|
||||||
await this.database.SaveChangesAsync();
|
await this.database.SaveChangesAsync();
|
||||||
|
|
||||||
return this.Ok();
|
return this.Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +53,7 @@ public class AdminSlotController : ControllerBase
|
||||||
public async Task<IActionResult> DeleteLevel([FromRoute] int id)
|
public async Task<IActionResult> DeleteLevel([FromRoute] int id)
|
||||||
{
|
{
|
||||||
User? user = this.database.UserFromWebRequest(this.Request);
|
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);
|
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id);
|
||||||
if (slot == null) return this.Ok();
|
if (slot == null) return this.Ok();
|
|
@ -30,7 +30,9 @@ public class CasePage : BaseLayout
|
||||||
|
|
||||||
this.SearchValue = name.Replace(" ", string.Empty);
|
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.CaseCount = await this.Database.Cases.CountAsync(c => c.CaseDescription.Contains(this.SearchValue));
|
||||||
|
|
||||||
this.PageNumber = pageNumber;
|
this.PageNumber = pageNumber;
|
||||||
|
|
|
@ -163,14 +163,14 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (Model.User != null && Model.User.IsAdmin)
|
@if (Model.User != null && Model.User.IsModerator)
|
||||||
{
|
{
|
||||||
<div class="ui yellow segment">
|
<div class="ui green segment">
|
||||||
<h2>Admin Options</h2>
|
<h2>Moderator Options</h2>
|
||||||
|
|
||||||
@if (Model.Slot?.TeamPick ?? false)
|
@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">
|
<div class="ui pink button">
|
||||||
<i class="ribbon icon"></i>
|
<i class="ribbon icon"></i>
|
||||||
<span>Remove Team Pick</span>
|
<span>Remove Team Pick</span>
|
||||||
|
@ -179,7 +179,7 @@
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<a href="/admin/slot/@Model.Slot?.SlotId/teamPick">
|
<a href="/moderation/slot/@Model.Slot?.SlotId/teamPick">
|
||||||
<div class="ui pink button">
|
<div class="ui pink button">
|
||||||
<i class="ribbon icon"></i>
|
<i class="ribbon icon"></i>
|
||||||
<span>Team Pick</span>
|
<span>Team Pick</span>
|
||||||
|
@ -187,7 +187,7 @@
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
|
||||||
<a href="/admin/slot/@Model.Slot?.SlotId/delete">
|
<a href="/moderation/slot/@Model.Slot?.SlotId/delete">
|
||||||
<div class="ui red button">
|
<div class="ui red button">
|
||||||
<i class="trash icon"></i>
|
<i class="trash icon"></i>
|
||||||
<span>Delete</span>
|
<span>Delete</span>
|
||||||
|
|
|
@ -44,4 +44,13 @@ public class ModerationCase
|
||||||
return database.Slots.FirstOrDefaultAsync(u => u.SlotId == this.AffectedId)!;
|
return database.Slots.FirstOrDefaultAsync(u => u.SlotId == this.AffectedId)!;
|
||||||
}
|
}
|
||||||
#endregion
|
#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