Changes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using maintenance.Data;
|
||||
using maintenance.Data.Entities;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@@ -17,6 +18,8 @@ public sealed class IndexModel : PageModel
|
||||
}
|
||||
|
||||
public IReadOnlyList<ManagedPageEntity> Templates { get; private set; } = [];
|
||||
[TempData]
|
||||
public string? StatusMessage { get; set; }
|
||||
|
||||
public async Task OnGetAsync()
|
||||
{
|
||||
@@ -28,8 +31,32 @@ public sealed class IndexModel : PageModel
|
||||
.ToListAsync(HttpContext.RequestAborted);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteAsync(Guid id)
|
||||
{
|
||||
var page = await _dbContext.ManagedPages
|
||||
.FirstOrDefaultAsync(t => t.Id == id, HttpContext.RequestAborted);
|
||||
|
||||
if (page is null)
|
||||
{
|
||||
StatusMessage = "Page was not found.";
|
||||
return RedirectToPage();
|
||||
}
|
||||
|
||||
if (page.IsDefaultFallback)
|
||||
{
|
||||
StatusMessage = "Default template pages cannot be deleted.";
|
||||
return RedirectToPage();
|
||||
}
|
||||
|
||||
_dbContext.ManagedPages.Remove(page);
|
||||
await _dbContext.SaveChangesAsync(HttpContext.RequestAborted);
|
||||
|
||||
StatusMessage = $"Deleted page '{page.Key}'.";
|
||||
return RedirectToPage();
|
||||
}
|
||||
|
||||
public string GetPreviewUrl(ManagedPageEntity page)
|
||||
{
|
||||
return $"/errors/{page.PageKind}?page={Uri.EscapeDataString(page.Key)}";
|
||||
return $"/{page.PageKind}?page={Uri.EscapeDataString(page.Key)}";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user