Swarm/DysonNetwork.Sphere/Pages/Spell/MagicSpellPage.cshtml.cs
LittleSheep a77d00c3b9 💄 Restyled web pages
🧱 Add tailwindcss
2025-05-17 15:40:39 +08:00

49 lines
1.5 KiB
C#

using DysonNetwork.Sphere.Account;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using NodaTime;
namespace DysonNetwork.Sphere.Pages.Spell;
public class MagicSpellPage(AppDatabase db, MagicSpellService spells) : PageModel
{
[BindProperty]
public MagicSpell? CurrentSpell { get; set; }
public bool IsSuccess { get; set; }
public async Task<IActionResult> OnGetAsync(string spellWord)
{
spellWord = Uri.UnescapeDataString(spellWord);
var now = SystemClock.Instance.GetCurrentInstant();
CurrentSpell = await db.MagicSpells
.Where(e => e.Spell == spellWord)
.Where(e => e.ExpiresAt == null || now < e.ExpiresAt)
.Where(e => e.AffectedAt == null || now >= e.AffectedAt)
.Include(e => e.Account)
.FirstOrDefaultAsync();
return Page();
}
public async Task<IActionResult> OnPostAsync()
{
if (CurrentSpell?.Id == null)
return Page();
var now = SystemClock.Instance.GetCurrentInstant();
var spell = await db.MagicSpells
.Where(e => e.Id == CurrentSpell.Id)
.Where(e => e.ExpiresAt == null || now < e.ExpiresAt)
.Where(e => e.AffectedAt == null || now >= e.AffectedAt)
.FirstOrDefaultAsync();
if (spell == null)
return Page();
await spells.ApplyMagicSpell(spell);
IsSuccess = true;
return Page();
}
}