60 lines
1.7 KiB
C#
60 lines
1.7 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Server.Data;
|
|
using Server.Data.Entities;
|
|
using Server.Data.Enums;
|
|
|
|
namespace VoidScavengers.Services.Admin.Pages.Mobs;
|
|
|
|
public class IndexModel : AdminPageModel
|
|
{
|
|
private readonly GameDbContext _db;
|
|
|
|
public IndexModel(GameDbContext db)
|
|
{
|
|
_db = db;
|
|
}
|
|
|
|
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(string? search, MobType? type, MobCategory? category)
|
|
{
|
|
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();
|
|
}
|
|
}
|