mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-29 16:38:37 +00:00
parent
841692addb
commit
6fb294a5b5
2 changed files with 120 additions and 6 deletions
|
@ -0,0 +1,73 @@
|
||||||
|
#nullable enable
|
||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace LBPUnion.ProjectLighthouse.Controllers.Website.Admin
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("admin/slot/{id:int}")]
|
||||||
|
public class AdminSlotController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly Database database;
|
||||||
|
|
||||||
|
public AdminSlotController(Database database)
|
||||||
|
{
|
||||||
|
this.database = database;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route("teamPick")]
|
||||||
|
public async Task<IActionResult> TeamPick([FromRoute] int id)
|
||||||
|
{
|
||||||
|
User? user = this.database.UserFromWebRequest(this.Request);
|
||||||
|
if (user == null || !user.IsAdmin) return this.StatusCode(403, "");
|
||||||
|
|
||||||
|
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id);
|
||||||
|
if (slot == null) return this.NotFound();
|
||||||
|
|
||||||
|
slot.TeamPick = true;
|
||||||
|
|
||||||
|
await this.database.SaveChangesAsync();
|
||||||
|
|
||||||
|
return this.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route("removeTeamPick")]
|
||||||
|
public async Task<IActionResult> RemoveTeamPick([FromRoute] int id)
|
||||||
|
{
|
||||||
|
User? user = this.database.UserFromWebRequest(this.Request);
|
||||||
|
if (user == null || !user.IsAdmin) return this.StatusCode(403, "");
|
||||||
|
|
||||||
|
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id);
|
||||||
|
if (slot == null) return this.NotFound();
|
||||||
|
|
||||||
|
slot.TeamPick = false;
|
||||||
|
|
||||||
|
await this.database.SaveChangesAsync();
|
||||||
|
|
||||||
|
return this.Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Route("delete")]
|
||||||
|
public async Task<IActionResult> DeleteLevel([FromRoute] int id)
|
||||||
|
{
|
||||||
|
User? user = this.database.UserFromWebRequest(this.Request);
|
||||||
|
if (user == null || !user.IsAdmin) return this.StatusCode(403, "");
|
||||||
|
|
||||||
|
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id);
|
||||||
|
if (slot == null) return this.Ok();
|
||||||
|
|
||||||
|
if (slot.Location == null) throw new ArgumentNullException();
|
||||||
|
|
||||||
|
this.database.Locations.Remove(slot.Location);
|
||||||
|
this.database.Slots.Remove(slot);
|
||||||
|
|
||||||
|
await this.database.SaveChangesAsync();
|
||||||
|
|
||||||
|
return this.Ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,21 +20,62 @@
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
<div class="ui grid">
|
<div class="ui grid">
|
||||||
<div class="eight wide column">
|
<div class="eight wide column">
|
||||||
<div class="ui blue segment">
|
<div class="ui blue segment">
|
||||||
<h2>Description</h2>
|
<h2>Description</h2>
|
||||||
<p>@Model.Slot.Description</p>
|
<p>@(string.IsNullOrEmpty(Model.Slot.Description) ? "This level has no description." : Model.Slot.Description)</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="eight wide column">
|
<div class="eight wide column">
|
||||||
<div class="ui red segment">
|
<div class="ui red segment">
|
||||||
<h2>Tags</h2>
|
<h2>Tags</h2>
|
||||||
@foreach (string label in Model.Slot.AuthorLabels.Split(",").Where(label => !string.IsNullOrEmpty(label)))
|
@{
|
||||||
{
|
string[] authorLabels = Model.Slot.AuthorLabels.Split(",");
|
||||||
<div class="ui blue label">@label.Replace("LABEL_", "")</div>
|
if (authorLabels.Length == 1) // ..?? ok c#
|
||||||
|
{
|
||||||
|
<p>This level has no tags.</p>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (string label in authorLabels.Where(label => !string.IsNullOrEmpty(label)))
|
||||||
|
{
|
||||||
|
<div class="ui blue label">@label.Replace("LABEL_", "")</div>
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@if (Model.User != null && Model.User.IsAdmin)
|
||||||
|
{
|
||||||
|
<div class="ui yellow segment">
|
||||||
|
<h2>Admin Settings</h2>
|
||||||
|
|
||||||
|
@if (Model.Slot.TeamPick)
|
||||||
|
{
|
||||||
|
<a href="/admin/slot/@Model.Slot.SlotId/removeTeamPick">
|
||||||
|
<div class="ui pink button">
|
||||||
|
<i class="ribbon icon"></i>
|
||||||
|
<span>Remove Team Pick</span>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<a href="/admin/slot/@Model.Slot.SlotId/teamPick">
|
||||||
|
<div class="ui pink button">
|
||||||
|
<i class="ribbon icon"></i>
|
||||||
|
<span>Team Pick</span>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
}
|
||||||
|
|
||||||
|
<a href="/admin/slot/@Model.Slot.SlotId/delete">
|
||||||
|
<div class="ui red button">
|
||||||
|
<i class="trash icon"></i>
|
||||||
|
<span>Delete</span>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue