using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using LittleShop.Services; using LittleShop.Enums; namespace LittleShop.Areas.Admin.Controllers; [Area("Admin")] [Authorize(AuthenticationSchemes = "Cookies", Roles = "Admin")] public class PaymentsController : Controller { private readonly ICryptoPaymentService _paymentService; private readonly IOrderService _orderService; private readonly ILogger _logger; public PaymentsController( ICryptoPaymentService paymentService, IOrderService orderService, ILogger _logger) { _paymentService = paymentService; _orderService = orderService; this._logger = _logger; } //GET: Admin/Payments public async Task Index(string? status = null) { try { var payments = await _paymentService.GetAllPaymentsAsync(); // Filter by status if provided if (!string.IsNullOrEmpty(status) && Enum.TryParse(status, out var paymentStatus)) { payments = payments.Where(p => p.Status == paymentStatus); ViewData["CurrentStatus"] = status; } // Get orders for payment-order linking var allOrders = await _orderService.GetAllOrdersAsync(); ViewData["Orders"] = allOrders.ToDictionary(o => o.Id, o => o); return View(payments.OrderByDescending(p => p.CreatedAt)); } catch (Exception ex) { _logger.LogError(ex, "Error retrieving payments list"); TempData["ErrorMessage"] = "Failed to load payments. Please try again."; return View(Enumerable.Empty()); } } }