- ASP.NET Core 8 REST API server - 12 API endpoints matching EA Synergy protocol - SQLite database with Entity Framework Core - Web admin panel with Bootstrap 5 - User, Catalog, Session, Purchase management - Comprehensive documentation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
57 lines
1.6 KiB
C#
57 lines
1.6 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using RR3CommunityServer.Data;
|
|
using static RR3CommunityServer.Data.RR3DbContext;
|
|
|
|
namespace RR3CommunityServer.Pages;
|
|
|
|
public class SessionsModel : PageModel
|
|
{
|
|
private readonly RR3DbContext _context;
|
|
|
|
public SessionsModel(RR3DbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public List<Session> AllSessions { get; set; } = new();
|
|
public List<Session> ActiveSessions { get; set; } = new();
|
|
public List<Session> ExpiredSessions { get; set; } = new();
|
|
|
|
public async Task OnGetAsync()
|
|
{
|
|
AllSessions = await _context.Sessions
|
|
.OrderByDescending(s => s.CreatedAt)
|
|
.ToListAsync();
|
|
|
|
var now = DateTime.UtcNow;
|
|
ActiveSessions = AllSessions.Where(s => s.ExpiresAt > now).ToList();
|
|
ExpiredSessions = AllSessions.Where(s => s.ExpiresAt <= now).ToList();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostDeleteAsync(int sessionId)
|
|
{
|
|
var session = await _context.Sessions.FindAsync(sessionId);
|
|
if (session != null)
|
|
{
|
|
_context.Sessions.Remove(session);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
return RedirectToPage();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostCleanupExpiredAsync()
|
|
{
|
|
var expiredSessions = await _context.Sessions
|
|
.Where(s => s.ExpiresAt <= DateTime.UtcNow)
|
|
.ToListAsync();
|
|
|
|
_context.Sessions.RemoveRange(expiredSessions);
|
|
await _context.SaveChangesAsync();
|
|
|
|
return RedirectToPage();
|
|
}
|
|
}
|