🐛 Fix magic spell and email service
This commit is contained in:
30
DysonNetwork.Sphere/Pages/Spell/MagicSpellPage.cshtml.cs
Normal file
30
DysonNetwork.Sphere/Pages/Spell/MagicSpellPage.cshtml.cs
Normal file
@ -0,0 +1,30 @@
|
||||
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
|
||||
{
|
||||
public async Task<IActionResult> OnGetAsync(string spellWord)
|
||||
{
|
||||
spellWord = Uri.UnescapeDataString(spellWord);
|
||||
var now = SystemClock.Instance.GetCurrentInstant();
|
||||
var spell = await db.MagicSpells
|
||||
.Where(e => e.Spell == spellWord)
|
||||
.Where(e => e.ExpiresAt == null || now < e.ExpiresAt)
|
||||
.Where(e => e.AffectedAt == null || now >= e.AffectedAt)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
ViewData["Spell"] = spell;
|
||||
|
||||
if (spell is not null)
|
||||
{
|
||||
await spells.ApplyMagicSpell(spell);
|
||||
}
|
||||
|
||||
return Page();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user