mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-05 02:12:26 +00:00
40 lines
No EOL
1.4 KiB
C#
40 lines
No EOL
1.4 KiB
C#
#nullable enable
|
|
using LBPUnion.ProjectLighthouse.Types;
|
|
using LBPUnion.ProjectLighthouse.Website.Pages.Layouts;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace LBPUnion.ProjectLighthouse.Website.Pages.Admin;
|
|
|
|
public class AdminSetGrantedSlotsPage : BaseLayout
|
|
{
|
|
public AdminSetGrantedSlotsPage(Database database) : base(database)
|
|
{}
|
|
|
|
public User? TargetedUser;
|
|
|
|
public async Task<IActionResult> OnGet([FromRoute] int id)
|
|
{
|
|
User? user = this.Database.UserFromWebRequest(this.Request);
|
|
if (user == null || !user.IsAdmin) return this.NotFound();
|
|
|
|
this.TargetedUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == id);
|
|
if (this.TargetedUser == null) return this.NotFound();
|
|
|
|
return this.Page();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPost([FromRoute] int id, int grantedSlotCount)
|
|
{
|
|
User? user = this.Database.UserFromWebRequest(this.Request);
|
|
if (user == null || !user.IsAdmin) return this.NotFound();
|
|
|
|
this.TargetedUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == id);
|
|
if (this.TargetedUser == null) return this.NotFound();
|
|
|
|
this.TargetedUser.AdminGrantedSlots = grantedSlotCount;
|
|
|
|
await this.Database.SaveChangesAsync();
|
|
return this.Redirect($"/user/{this.TargetedUser.UserId}");
|
|
}
|
|
} |