diff --git a/ProjectLighthouse/Controllers/Website/Admin/AdminSlotController.cs b/ProjectLighthouse/Controllers/Website/Admin/AdminSlotController.cs new file mode 100644 index 00000000..70c973ef --- /dev/null +++ b/ProjectLighthouse/Controllers/Website/Admin/AdminSlotController.cs @@ -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 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 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 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(); + } + } +} \ No newline at end of file diff --git a/ProjectLighthouse/Pages/SlotPage.cshtml b/ProjectLighthouse/Pages/SlotPage.cshtml index 5faf620d..221d99f2 100644 --- a/ProjectLighthouse/Pages/SlotPage.cshtml +++ b/ProjectLighthouse/Pages/SlotPage.cshtml @@ -20,21 +20,62 @@ }, }) -

Description

-

@Model.Slot.Description

+

@(string.IsNullOrEmpty(Model.Slot.Description) ? "This level has no description." : Model.Slot.Description)

Tags

- @foreach (string label in Model.Slot.AuthorLabels.Split(",").Where(label => !string.IsNullOrEmpty(label))) - { -
@label.Replace("LABEL_", "")
+ @{ + string[] authorLabels = Model.Slot.AuthorLabels.Split(","); + if (authorLabels.Length == 1) // ..?? ok c# + { +

This level has no tags.

+ } + else + { + foreach (string label in authorLabels.Where(label => !string.IsNullOrEmpty(label))) + { +
@label.Replace("LABEL_", "")
+ } + } }
-
\ No newline at end of file + +@if (Model.User != null && Model.User.IsAdmin) +{ +
+

Admin Settings

+ + @if (Model.Slot.TeamPick) + { + +
+ + Remove Team Pick +
+
+ } + else + { + +
+ + Team Pick +
+
+ } + + +
+ + Delete +
+
+
+} \ No newline at end of file