From 305f782565e3470ddd983c5780f83ad939f2b655 Mon Sep 17 00:00:00 2001 From: dingo Date: Thu, 25 Dec 2025 15:36:03 -0500 Subject: [PATCH] Admin v9 --- Services/Admin/Pages/Assets/Index.cshtml | 202 +++++++++++- Services/Admin/Pages/Assets/Index.cshtml.cs | 57 +++- Services/Admin/Pages/Items/Index.cshtml.cs | 28 +- Services/Admin/Pages/Mobs/Index.cshtml.cs | 29 +- Services/Admin/Pages/Recipes/Edit.cshtml | 304 +++++++++++++++++++ Services/Admin/Pages/Recipes/Edit.cshtml.cs | 172 +++++++++++ Services/Admin/Pages/Recipes/Index.cshtml | 198 +++++++++++- Services/Admin/Pages/Recipes/Index.cshtml.cs | 67 +++- 8 files changed, 1021 insertions(+), 36 deletions(-) create mode 100644 Services/Admin/Pages/Recipes/Edit.cshtml create mode 100644 Services/Admin/Pages/Recipes/Edit.cshtml.cs diff --git a/Services/Admin/Pages/Assets/Index.cshtml b/Services/Admin/Pages/Assets/Index.cshtml index 5c51bfc..30fdfe4 100644 --- a/Services/Admin/Pages/Assets/Index.cshtml +++ b/Services/Admin/Pages/Assets/Index.cshtml @@ -1,16 +1,208 @@ @page "/admin/assets" @model Assets.IndexModel +@using Server.Data.Entities @{ ViewData["Title"] = "CDN Assets"; }
-
-

CDN Assets

-

Browse assets (@Model.AssetCount total)

+ +
+
+

CDN Assets

+

Browse and manage client assets

+
+ + + + + Add Asset +
-
-

Asset browser coming soon...

+ +
+
+
+ + +
+
+ + +
+ + Clear +
+ + +
+
+

@Model.TotalCount

+

Total Assets

+
+
+

@Model.TextureCount

+

Textures

+
+
+

@Model.SceneCount

+

Scenes

+
+
+

@Model.ScriptCount

+

Scripts

+
+
+ + +
+ @foreach (var asset in Model.Assets) + { +
+ +
+ @if (asset.AssetType == ClientAssetType.Texture) + { + @asset.FilePath + } + else + { +
+ @switch (asset.AssetType) + { + case ClientAssetType.Scene: + + + + break; + case ClientAssetType.Script: + + + + break; + case ClientAssetType.Audio: + + + + break; + default: + + + + break; + } +

@asset.AssetType

+
+ } + + +
+ + @asset.AssetType + +
+
+ + +
+

+ @System.IO.Path.GetFileName(asset.FilePath) +

+

+ @asset.FilePath +

+
+ v@asset.Version + @FormatFileSize(asset.FileSize) +
+
+ @if (asset.IsRequired) + { + Required + } + @if (!asset.IsEnabled) + { + Disabled + } +
+
+ + +
+ + + + + + +
+
+ } + + @if (!Model.Assets.Any()) + { +
+ + + +

No assets found.

+
+ } +
+ + + @if (Model.TotalPages > 1) + { +
+

+ Showing @((Model.CurrentPage - 1) * Model.PageSize + 1)-@Math.Min(Model.CurrentPage * Model.PageSize, Model.TotalCount) of @Model.TotalCount +

+
+ @if (Model.CurrentPage > 1) + { + ← Prev + } + @Model.CurrentPage / @Model.TotalPages + @if (Model.CurrentPage < Model.TotalPages) + { + Next → + } +
+
+ }
+ +@functions { + string FormatFileSize(long bytes) + { + if (bytes < 1024) return $"{bytes} B"; + if (bytes < 1024 * 1024) return $"{bytes / 1024.0:F1} KB"; + return $"{bytes / (1024.0 * 1024.0):F1} MB"; + } +} + +@section Scripts { + +} diff --git a/Services/Admin/Pages/Assets/Index.cshtml.cs b/Services/Admin/Pages/Assets/Index.cshtml.cs index d5de1a7..394f975 100644 --- a/Services/Admin/Pages/Assets/Index.cshtml.cs +++ b/Services/Admin/Pages/Assets/Index.cshtml.cs @@ -1,5 +1,7 @@ +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; +using Server.Data.Entities; namespace VoidScavengers.Services.Admin.Pages.Assets; @@ -12,10 +14,61 @@ public class IndexModel : AdminPageModel _db = db; } - public int AssetCount { get; set; } + public List Assets { get; set; } = new(); + + [FromQuery(Name = "search")] + public string? Search { get; set; } + + [FromQuery(Name = "type")] + public ClientAssetType? TypeFilter { get; set; } + + [FromQuery(Name = "page")] + public int CurrentPage { get; set; } = 1; + + public int PageSize { get; set; } = 24; + public int TotalCount { get; set; } + public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize); + + public int TextureCount { get; set; } + public int SceneCount { get; set; } + public int ScriptCount { get; set; } + + public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com"; + + public string GetPageUrl(int page) + { + var parts = new List { $"page={page}" }; + if (!string.IsNullOrEmpty(Search)) parts.Add($"search={Uri.EscapeDataString(Search)}"); + if (TypeFilter.HasValue) parts.Add($"type={TypeFilter}"); + return "/admin/assets?" + string.Join("&", parts); + } public async Task OnGetAsync() { - AssetCount = await _db.ClientAssets.CountAsync(); + if (CurrentPage < 1) CurrentPage = 1; + + var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL"); + if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl; + + // Stats + TextureCount = await _db.ClientAssets.CountAsync(a => a.AssetType == ClientAssetType.Texture); + SceneCount = await _db.ClientAssets.CountAsync(a => a.AssetType == ClientAssetType.Scene); + ScriptCount = await _db.ClientAssets.CountAsync(a => a.AssetType == ClientAssetType.Script); + + var query = _db.ClientAssets.AsQueryable(); + + if (!string.IsNullOrWhiteSpace(Search)) + query = query.Where(a => a.FilePath.Contains(Search)); + + if (TypeFilter.HasValue) + query = query.Where(a => a.AssetType == TypeFilter.Value); + + TotalCount = await query.CountAsync(); + + Assets = await query + .OrderByDescending(a => a.UpdatedAt) + .Skip((CurrentPage - 1) * PageSize) + .Take(PageSize) + .ToListAsync(); } } diff --git a/Services/Admin/Pages/Items/Index.cshtml.cs b/Services/Admin/Pages/Items/Index.cshtml.cs index 96af107..fd24702 100644 --- a/Services/Admin/Pages/Items/Index.cshtml.cs +++ b/Services/Admin/Pages/Items/Index.cshtml.cs @@ -16,10 +16,19 @@ public class IndexModel : AdminPageModel } public List Items { get; set; } = new(); + + [FromQuery(Name = "search")] public string? Search { get; set; } + + [FromQuery(Name = "type")] public ItemType? TypeFilter { get; set; } + + [FromQuery(Name = "rarity")] public ItemRarity? RarityFilter { get; set; } + + [FromQuery(Name = "page")] 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); @@ -34,26 +43,23 @@ public class IndexModel : AdminPageModel return "/admin/items?" + string.Join("&", parts); } - public async Task OnGetAsync(string? search, ItemType? type, ItemRarity? rarity, int page = 1) + public async Task OnGetAsync() { - Search = search; - TypeFilter = type; - RarityFilter = rarity; - CurrentPage = Math.Max(1, page); + if (CurrentPage < 1) CurrentPage = 1; 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 (!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 (TypeFilter.HasValue) + query = query.Where(i => i.Type == TypeFilter.Value); - if (rarity.HasValue) - query = query.Where(i => i.Rarity == rarity.Value); + if (RarityFilter.HasValue) + query = query.Where(i => i.Rarity == RarityFilter.Value); TotalCount = await query.CountAsync(); diff --git a/Services/Admin/Pages/Mobs/Index.cshtml.cs b/Services/Admin/Pages/Mobs/Index.cshtml.cs index 86815c3..8d5a285 100644 --- a/Services/Admin/Pages/Mobs/Index.cshtml.cs +++ b/Services/Admin/Pages/Mobs/Index.cshtml.cs @@ -16,10 +16,19 @@ public class IndexModel : AdminPageModel } public List Mobs { get; set; } = new(); + + [FromQuery(Name = "search")] public string? Search { get; set; } + + [FromQuery(Name = "type")] public MobType? TypeFilter { get; set; } + + [FromQuery(Name = "category")] public MobCategory? CategoryFilter { get; set; } + + [FromQuery(Name = "page")] 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); @@ -33,23 +42,20 @@ public class IndexModel : AdminPageModel return "/admin/mobs?" + string.Join("&", parts); } - public async Task OnGetAsync(string? search, MobType? type, MobCategory? category, int page = 1) + public async Task OnGetAsync() { - Search = search; - TypeFilter = type; - CategoryFilter = category; - CurrentPage = Math.Max(1, page); + if (CurrentPage < 1) CurrentPage = 1; var query = _db.DungeonMobDefinitions.AsQueryable(); - if (!string.IsNullOrWhiteSpace(search)) - query = query.Where(m => m.Name.Contains(search) || m.Description.Contains(search)); + 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 (TypeFilter.HasValue) + query = query.Where(m => m.Type == TypeFilter.Value); - if (category.HasValue) - query = query.Where(m => m.Category == category.Value); + if (CategoryFilter.HasValue) + query = query.Where(m => m.Category == CategoryFilter.Value); TotalCount = await query.CountAsync(); @@ -65,7 +71,6 @@ public class IndexModel : AdminPageModel 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); diff --git a/Services/Admin/Pages/Recipes/Edit.cshtml b/Services/Admin/Pages/Recipes/Edit.cshtml new file mode 100644 index 0000000..63db539 --- /dev/null +++ b/Services/Admin/Pages/Recipes/Edit.cshtml @@ -0,0 +1,304 @@ +@page "/admin/recipes/edit" +@model Recipes.EditModel +@using Server.Data.Entities +@{ + ViewData["Title"] = Model.IsNew ? "Create Recipe" : $"Edit: {Model.Recipe.Name}"; +} + +
+ +
+ + + + + +
+

@(Model.IsNew ? "Create Recipe" : "Edit Recipe")

+

@(Model.IsNew ? "Add a new crafting recipe" : $"ID: {Model.Recipe.Id}")

+
+
+ + @if (!string.IsNullOrEmpty(Model.Message)) + { +
+ @Model.Message +
+ } + +
+ @Html.AntiForgeryToken() + + + +
+
+

Basic Information

+
+
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + + +
+
+
+ + +
+
+

Output

+
+
+
+ + +
+
+ + +
+
+
+ + +
+ + Cancel +
+
+ + + @if (!Model.IsNew) + { +
+
+

Ingredients (@Model.Ingredients.Count)

+ +
+ + +
+
+ +
+ @for (int i = 0; i < 16; i++) + { + var ingredient = Model.Ingredients.FirstOrDefault(ing => ing.SlotOrder == i); +
+ @if (ingredient != null) + { + @if (ingredient.ItemDefinition != null && !string.IsNullOrEmpty(ingredient.ItemDefinition.SpritePath)) + { + + } + else + { + @ingredient.ItemDefinition?.Name?.Substring(0, Math.Min(3, ingredient.ItemDefinition?.Name?.Length ?? 0)) + } + @if (ingredient.Quantity > 1) + { + @ingredient.Quantity + } + + + + } + else + { + @i + } +
+ } +
+ + +
→
+ + +
+ @if (Model.Recipe.OutputItem != null && !string.IsNullOrEmpty(Model.Recipe.OutputItem.SpritePath)) + { + + } + else + { + @Model.Recipe.OutputItem?.Name + } + @if (Model.Recipe.OutputQuantity > 1) + { + @Model.Recipe.OutputQuantity + } +
+
+
+ + +
+ + + + + + + + + + + + @foreach (var ing in Model.Ingredients.OrderBy(i => i.SlotOrder)) + { + + + + + + + + } + @if (!Model.Ingredients.Any()) + { + + + + } + +
SlotIconItemQuantityActions
@ing.SlotOrder + @if (ing.ItemDefinition != null && !string.IsNullOrEmpty(ing.ItemDefinition.SpritePath)) + { + + } + + @ing.ItemDefinition?.Name + (ID: @ing.ItemDefinitionId) + @ing.Quantity +
+ @Html.AntiForgeryToken() + + + +
+
+ No ingredients yet. Add items to create the recipe. +
+
+
+ + + + } +
+ +@section Scripts { + +} diff --git a/Services/Admin/Pages/Recipes/Edit.cshtml.cs b/Services/Admin/Pages/Recipes/Edit.cshtml.cs new file mode 100644 index 0000000..2928aa0 --- /dev/null +++ b/Services/Admin/Pages/Recipes/Edit.cshtml.cs @@ -0,0 +1,172 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using Server.Data; +using Server.Data.Entities; + +namespace VoidScavengers.Services.Admin.Pages.Recipes; + +public class EditModel : AdminPageModel +{ + private readonly GameDbContext _db; + + public EditModel(GameDbContext db) + { + _db = db; + } + + [BindProperty] + public DungeonCraftingRecipe Recipe { get; set; } = new(); + + public List Ingredients { get; set; } = new(); + public List AllItems { get; set; } = new(); + + public bool IsNew => Recipe.Id == 0; + public string? Message { get; set; } + public bool IsError { get; set; } + public string CdnBaseUrl { get; set; } = "https://assets.aeternalisgames.com"; + + public async Task OnGetAsync(int? id) + { + var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL"); + if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl; + + AllItems = await _db.DungeonItemDefinitions + .Where(i => i.IsEnabled) + .OrderBy(i => i.Type) + .ThenBy(i => i.Name) + .ToListAsync(); + + if (id.HasValue) + { + var recipe = await _db.DungeonCraftingRecipes + .Include(r => r.OutputItem) + .FirstOrDefaultAsync(r => r.Id == id.Value); + + if (recipe != null) + { + Recipe = recipe; + Ingredients = await _db.DungeonCraftingRecipeIngredients + .Include(i => i.ItemDefinition) + .Where(i => i.RecipeId == id.Value) + .OrderBy(i => i.SlotOrder) + .ToListAsync(); + } + } + else + { + Recipe.IsEnabled = true; + Recipe.RequiredLevel = 1; + Recipe.Tier = 1; + Recipe.OutputQuantity = 1; + Recipe.BaseXp = 25; + } + } + + public async Task OnPostAsync() + { + var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL"); + if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl; + + AllItems = await _db.DungeonItemDefinitions.Where(i => i.IsEnabled).OrderBy(i => i.Name).ToListAsync(); + + Recipe.IsEnabled = Request.Form.ContainsKey("Recipe.IsEnabled"); + Recipe.IsBaseRecipe = Request.Form.ContainsKey("Recipe.IsBaseRecipe"); + Recipe.HasStatRolls = Request.Form.ContainsKey("Recipe.HasStatRolls"); + + if (string.IsNullOrWhiteSpace(Recipe.Name)) + { + Message = "Name is required."; + IsError = true; + return Page(); + } + + if (Recipe.OutputItemDefinitionId == 0) + { + Message = "Output item is required."; + IsError = true; + return Page(); + } + + try + { + if (Recipe.Id == 0) + { + _db.DungeonCraftingRecipes.Add(Recipe); + await _db.SaveChangesAsync(); + Message = $"Recipe '{Recipe.Name}' created. Now add ingredients below."; + return RedirectToPage("/Recipes/Edit", new { id = Recipe.Id }); + } + else + { + var existing = await _db.DungeonCraftingRecipes.FindAsync(Recipe.Id); + if (existing == null) + { + Message = "Recipe not found."; + IsError = true; + return Page(); + } + + existing.Name = Recipe.Name; + existing.Description = Recipe.Description; + existing.SkillType = Recipe.SkillType; + existing.RequiredLevel = Recipe.RequiredLevel; + existing.OutputItemDefinitionId = Recipe.OutputItemDefinitionId; + existing.OutputQuantity = Recipe.OutputQuantity; + existing.Tier = Recipe.Tier; + existing.BaseXp = Recipe.BaseXp; + existing.IsBaseRecipe = Recipe.IsBaseRecipe; + existing.HasStatRolls = Recipe.HasStatRolls; + existing.IsEnabled = Recipe.IsEnabled; + + await _db.SaveChangesAsync(); + + Recipe = await _db.DungeonCraftingRecipes + .Include(r => r.OutputItem) + .FirstAsync(r => r.Id == existing.Id); + + Ingredients = await _db.DungeonCraftingRecipeIngredients + .Include(i => i.ItemDefinition) + .Where(i => i.RecipeId == Recipe.Id) + .OrderBy(i => i.SlotOrder) + .ToListAsync(); + + Message = "Changes saved successfully."; + } + } + catch (Exception ex) + { + Message = $"Error: {ex.Message}"; + IsError = true; + } + + return Page(); + } + + public async Task OnPostAddIngredientAsync(int recipeId, int itemId, int slotOrder, int quantity) + { + var ingredient = new DungeonCraftingRecipeIngredient + { + RecipeId = recipeId, + ItemDefinitionId = itemId, + SlotOrder = slotOrder, + Quantity = quantity + }; + + _db.DungeonCraftingRecipeIngredients.Add(ingredient); + await _db.SaveChangesAsync(); + + return RedirectToPage("/Recipes/Edit", new { id = recipeId }); + } + + public async Task OnPostRemoveIngredientAsync(int ingredientId, int recipeId) + { + var ingredient = await _db.DungeonCraftingRecipeIngredients.FindAsync(ingredientId); + if (ingredient != null) + { + _db.DungeonCraftingRecipeIngredients.Remove(ingredient); + await _db.SaveChangesAsync(); + } + + return RedirectToPage("/Recipes/Edit", new { id = recipeId }); + } +} diff --git a/Services/Admin/Pages/Recipes/Index.cshtml b/Services/Admin/Pages/Recipes/Index.cshtml index d1ea246..ef66673 100644 --- a/Services/Admin/Pages/Recipes/Index.cshtml +++ b/Services/Admin/Pages/Recipes/Index.cshtml @@ -1,14 +1,16 @@ @page "/admin/recipes" @model Recipes.IndexModel +@using Server.Data.Entities @{ ViewData["Title"] = "Recipes"; }
+
-

Recipes

-

Manage crafting recipes (@Model.RecipeCount total)

+

Crafting Recipes

+

Manage crafting recipes

@@ -18,7 +20,195 @@
-
-

Recipe editor coming soon...

+ +
+
+
+ + +
+
+ + +
+ + Clear +
+
+ + +
+ + + + + + + + + + + + + + + + @foreach (var recipe in Model.Recipes) + { + + + + + + + + + + + + } + @if (!Model.Recipes.Any()) + { + + + + } + +
IDRecipeOutputSkillLvlIngredientsBaseEnabledActions
@recipe.Id + @recipe.Name + @if (!string.IsNullOrEmpty(recipe.Description)) + { +

@recipe.Description

+ } +
+ @if (recipe.OutputItem != null) + { +
+ @if (!string.IsNullOrEmpty(recipe.OutputItem.SpritePath)) + { + + } +
+ @recipe.OutputItem.Name + @if (recipe.OutputQuantity > 1) + { + x@recipe.OutputQuantity + } +
+
+ } + else + { + Missing Item #@recipe.OutputItemDefinitionId + } +
+ @recipe.SkillType + @recipe.RequiredLevel + @recipe.Ingredients.Count + + @if (recipe.IsBaseRecipe) + { + ✓ + } + else + { + - + } + + @if (recipe.IsEnabled) + { + + } + else + { + + } + +
+ + + + + + +
+
+ No recipes found. Create one? +
+
+ + + @if (Model.TotalPages > 1) + { +
+

+ Showing @((Model.CurrentPage - 1) * Model.PageSize + 1)-@Math.Min(Model.CurrentPage * Model.PageSize, Model.TotalCount) of @Model.TotalCount +

+
+ @if (Model.CurrentPage > 1) + { + ← Prev + } + @Model.CurrentPage / @Model.TotalPages + @if (Model.CurrentPage < Model.TotalPages) + { + Next → + } +
+
+ } +
+ + + + +@functions { + string GetSkillBadgeClass(CraftingSkillType skill) => skill switch + { + CraftingSkillType.Smithing => "badge-common", + CraftingSkillType.Fletching => "badge-uncommon", + CraftingSkillType.Jewelry => "badge-rare", + CraftingSkillType.Alchemy => "badge-epic", + CraftingSkillType.Academic => "badge-legendary", + _ => "badge-common" + }; +} + +@section Scripts { + +} diff --git a/Services/Admin/Pages/Recipes/Index.cshtml.cs b/Services/Admin/Pages/Recipes/Index.cshtml.cs index 7f14ba4..7df040c 100644 --- a/Services/Admin/Pages/Recipes/Index.cshtml.cs +++ b/Services/Admin/Pages/Recipes/Index.cshtml.cs @@ -1,5 +1,7 @@ +using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Server.Data; +using Server.Data.Entities; namespace VoidScavengers.Services.Admin.Pages.Recipes; @@ -12,10 +14,71 @@ public class IndexModel : AdminPageModel _db = db; } - public int RecipeCount { get; set; } + public List Recipes { get; set; } = new(); + + [FromQuery(Name = "search")] + public string? Search { get; set; } + + [FromQuery(Name = "skill")] + public CraftingSkillType? SkillFilter { get; set; } + + [FromQuery(Name = "page")] + 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 string GetPageUrl(int page) + { + var parts = new List { $"page={page}" }; + if (!string.IsNullOrEmpty(Search)) parts.Add($"search={Uri.EscapeDataString(Search)}"); + if (SkillFilter.HasValue) parts.Add($"skill={SkillFilter}"); + return "/admin/recipes?" + string.Join("&", parts); + } public async Task OnGetAsync() { - RecipeCount = await _db.DungeonCraftingRecipes.CountAsync(); + if (CurrentPage < 1) CurrentPage = 1; + + var cdnUrl = Environment.GetEnvironmentVariable("CDN_BASE_URL"); + if (!string.IsNullOrEmpty(cdnUrl)) CdnBaseUrl = cdnUrl; + + var query = _db.DungeonCraftingRecipes + .Include(r => r.OutputItem) + .Include(r => r.Ingredients) + .AsQueryable(); + + if (!string.IsNullOrWhiteSpace(Search)) + query = query.Where(r => r.Name.Contains(Search) || r.Description.Contains(Search)); + + if (SkillFilter.HasValue) + query = query.Where(r => r.SkillType == SkillFilter.Value); + + TotalCount = await query.CountAsync(); + + Recipes = await query + .OrderBy(r => r.SkillType) + .ThenBy(r => r.RequiredLevel) + .ThenBy(r => r.Id) + .Skip((CurrentPage - 1) * PageSize) + .Take(PageSize) + .ToListAsync(); + } + + public async Task OnPostDeleteAsync(int id) + { + var recipe = await _db.DungeonCraftingRecipes + .Include(r => r.Ingredients) + .FirstOrDefaultAsync(r => r.Id == id); + + if (recipe != null) + { + _db.DungeonCraftingRecipeIngredients.RemoveRange(recipe.Ingredients); + _db.DungeonCraftingRecipes.Remove(recipe); + await _db.SaveChangesAsync(); + } + return RedirectToPage(); } }