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.Mobs;
|
||||
|
||||
@@ -12,10 +15,45 @@ public class IndexModel : AdminPageModel
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public int MobCount { get; set; }
|
||||
public List<DungeonMobDefinition> Mobs { get; set; } = new();
|
||||
public string? Search { get; set; }
|
||||
public MobType? TypeFilter { get; set; }
|
||||
public MobCategory? CategoryFilter { get; set; }
|
||||
|
||||
public async Task OnGetAsync()
|
||||
public async Task OnGetAsync(string? search, MobType? type, MobCategory? category)
|
||||
{
|
||||
MobCount = await _db.DungeonMobDefinitions.CountAsync();
|
||||
Search = search;
|
||||
TypeFilter = type;
|
||||
CategoryFilter = category;
|
||||
|
||||
var query = _db.DungeonMobDefinitions.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(search))
|
||||
query = query.Where(m => m.Name.Contains(search) || m.Description.Contains(search));
|
||||
|
||||
if (type.HasValue)
|
||||
query = query.Where(m => m.Type == type.Value);
|
||||
|
||||
if (category.HasValue)
|
||||
query = query.Where(m => m.Category == category.Value);
|
||||
|
||||
Mobs = await query
|
||||
.OrderBy(m => m.Id)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostDeleteAsync(int id)
|
||||
{
|
||||
var mob = await _db.DungeonMobDefinitions.FindAsync(id);
|
||||
if (mob != null)
|
||||
{
|
||||
// Also delete loot table mappings
|
||||
var mappings = await _db.DungeonMobLootTables.Where(m => m.MobDefinitionId == id).ToListAsync();
|
||||
_db.DungeonMobLootTables.RemoveRange(mappings);
|
||||
|
||||
_db.DungeonMobDefinitions.Remove(mob);
|
||||
await _db.SaveChangesAsync();
|
||||
}
|
||||
return RedirectToPage();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user