Admin Panel v6
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Server.Data;
|
||||
using Server.Data.Entities;
|
||||
using Server.Data.Enums;
|
||||
|
||||
namespace VoidScavengers.Services.Admin.Pages.Items;
|
||||
|
||||
@@ -12,10 +15,54 @@ public class IndexModel : AdminPageModel
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public int ItemCount { get; set; }
|
||||
public List<DungeonItemDefinition> Items { get; set; } = new();
|
||||
public string? Search { get; set; }
|
||||
public ItemType? TypeFilter { get; set; }
|
||||
public ItemRarity? RarityFilter { get; set; }
|
||||
public int CurrentPage { 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()
|
||||
public async Task OnGetAsync(string? search, ItemType? type, ItemRarity? rarity, int page = 1)
|
||||
{
|
||||
ItemCount = await _db.DungeonItemDefinitions.CountAsync();
|
||||
Search = search;
|
||||
TypeFilter = type;
|
||||
RarityFilter = rarity;
|
||||
CurrentPage = Math.Max(1, page);
|
||||
|
||||
var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL");
|
||||
if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl;
|
||||
|
||||
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((CurrentPage - 1) * PageSize)
|
||||
.Take(PageSize)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
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