Files
MoneyMap/MoneyMap/Pages/AccountDetails.cshtml.cs
AJ 1c28d9cc88 Refactor: remove unnecessary using directives
Removed unused using statements from page models and test files:
- Removed unused Microsoft.EntityFrameworkCore and MoneyMap.Data imports
- Removed redundant Xunit usings (already declared as global)

Fixes CS8019 and CS8933 hidden diagnostics.
2025-11-16 11:53:50 -05:00

63 lines
1.8 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using MoneyMap.Models;
using MoneyMap.Services;
namespace MoneyMap.Pages
{
public class AccountDetailsModel : PageModel
{
private readonly IAccountService _accountService;
private readonly ICardService _cardService;
public AccountDetailsModel(IAccountService accountService, ICardService cardService)
{
_accountService = accountService;
_cardService = cardService;
}
public Account Account { get; set; } = null!;
public List<CardWithStats> Cards { get; set; } = new();
public int TransactionCount { get; set; }
[TempData]
public string? SuccessMessage { get; set; }
[TempData]
public string? ErrorMessage { get; set; }
public async Task<IActionResult> OnGetAsync(int id)
{
var accountDetails = await _accountService.GetAccountDetailsAsync(id);
if (accountDetails == null)
return NotFound();
Account = accountDetails.Account;
Cards = accountDetails.Cards;
TransactionCount = accountDetails.TransactionCount;
return Page();
}
public async Task<IActionResult> OnPostDeleteCardAsync(int cardId)
{
// Get card to retrieve account ID before deletion
var card = await _cardService.GetCardByIdAsync(cardId);
var accountId = card?.AccountId;
var result = await _cardService.DeleteCardAsync(cardId);
if (result.Success)
{
SuccessMessage = result.Message;
}
else
{
ErrorMessage = result.Message;
}
return RedirectToPage(new { id = accountId });
}
}
}