Admin v9
This commit is contained in:
@@ -16,10 +16,19 @@ public class IndexModel : AdminPageModel
|
||||
}
|
||||
|
||||
public List<DungeonItemDefinition> 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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user