59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using MoneyMap.Services;
|
|
|
|
namespace MoneyMap.Pages
|
|
{
|
|
public class CategoryMappingsModel : PageModel
|
|
{
|
|
private readonly ITransactionCategorizer _categorizer;
|
|
|
|
public CategoryMappingsModel(ITransactionCategorizer categorizer)
|
|
{
|
|
_categorizer = categorizer;
|
|
}
|
|
|
|
public List<CategoryGroup> CategoryGroups { get; set; } = new();
|
|
public int TotalMappings { get; set; }
|
|
public int TotalCategories { get; set; }
|
|
|
|
[TempData]
|
|
public string? SuccessMessage { get; set; }
|
|
|
|
public async Task OnGetAsync()
|
|
{
|
|
var mappings = await _categorizer.GetAllMappingsAsync();
|
|
|
|
CategoryGroups = mappings
|
|
.GroupBy(m => m.Category)
|
|
.Select(g => new CategoryGroup
|
|
{
|
|
Category = g.Key,
|
|
Patterns = g.Select(m => m.Pattern).ToList(),
|
|
Count = g.Count()
|
|
})
|
|
.OrderBy(g => g.Category)
|
|
.ToList();
|
|
|
|
TotalMappings = mappings.Count;
|
|
TotalCategories = CategoryGroups.Count;
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostSeedDefaultsAsync()
|
|
{
|
|
await _categorizer.SeedDefaultMappingsAsync();
|
|
SuccessMessage = "Default category mappings loaded successfully!";
|
|
return RedirectToPage();
|
|
}
|
|
|
|
public class CategoryGroup
|
|
{
|
|
public required string Category { get; set; }
|
|
public required List<string> Patterns { get; set; }
|
|
public int Count { get; set; }
|
|
}
|
|
}
|
|
} |