AdminPanel
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
using Server.Data.Entities;
|
||||
using Server.Data.Enums;
|
||||
|
||||
namespace VoidScavengers.Admin.Pages.Items;
|
||||
|
||||
public class IndexModel : AdminPageModel
|
||||
{
|
||||
private readonly GameDbContext _db;
|
||||
|
||||
public IndexModel(GameDbContext db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public List<DungeonItemDefinition> Items { get; set; } = new();
|
||||
public string? Search { get; set; }
|
||||
public ItemType? TypeFilter { get; set; }
|
||||
public ItemRarity? RarityFilter { get; set; }
|
||||
public int Page { get; set; } = 1;
|
||||
public int PageSize { get; set; } = 20;
|
||||
public int TotalCount { get; set; }
|
||||
public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
|
||||
public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com";
|
||||
|
||||
public async Task OnGetAsync(string? search, ItemType? type, ItemRarity? rarity, int page = 1)
|
||||
{
|
||||
Search = search;
|
||||
TypeFilter = type;
|
||||
RarityFilter = rarity;
|
||||
Page = Math.Max(1, page);
|
||||
|
||||
var query = _db.DungeonItemDefinitions.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(search))
|
||||
{
|
||||
query = query.Where(i => i.Name.Contains(search) || i.Description.Contains(search));
|
||||
}
|
||||
|
||||
if (type.HasValue)
|
||||
{
|
||||
query = query.Where(i => i.Type == type.Value);
|
||||
}
|
||||
|
||||
if (rarity.HasValue)
|
||||
{
|
||||
query = query.Where(i => i.Rarity == rarity.Value);
|
||||
}
|
||||
|
||||
TotalCount = await query.CountAsync();
|
||||
|
||||
Items = await query
|
||||
.OrderBy(i => i.Id)
|
||||
.Skip((Page - 1) * PageSize)
|
||||
.Take(PageSize)
|
||||
.ToListAsync();
|
||||
|
||||
// Get CDN URL from environment if set
|
||||
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
|
||||
if (!string.IsNullOrEmpty(cdnUrl))
|
||||
{
|
||||
CdnBaseUrl = cdnUrl;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteAsync(int id)
|
||||
{
|
||||
var item = await _db.DungeonItemDefinitions.FindAsync(id);
|
||||
if (item != null)
|
||||
{
|
||||
_db.DungeonItemDefinitions.Remove(item);
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
return RedirectToPage();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user