Added connection string display to System Information section of dashboard. - Injected IConfiguration into DashboardController - Added ConnectionString to ViewData - Displayed in monospace code format for easy reading - Shows actual runtime connection string from configuration - Helps verify which database file is being used in different environments This makes it easier to troubleshoot database location issues, especially when deploying to different environments (Development, Production, CT109, etc.). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
58 lines
2.3 KiB
C#
58 lines
2.3 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using LittleShop.Services;
|
|
|
|
namespace LittleShop.Areas.Admin.Controllers;
|
|
|
|
[Area("Admin")]
|
|
[Authorize(Policy = "AdminOnly")]
|
|
public class DashboardController : Controller
|
|
{
|
|
private readonly IOrderService _orderService;
|
|
private readonly IProductService _productService;
|
|
private readonly ICategoryService _categoryService;
|
|
private readonly IConfiguration _configuration;
|
|
|
|
public DashboardController(
|
|
IOrderService orderService,
|
|
IProductService productService,
|
|
ICategoryService categoryService,
|
|
IConfiguration configuration)
|
|
{
|
|
_orderService = orderService;
|
|
_productService = productService;
|
|
_categoryService = categoryService;
|
|
_configuration = configuration;
|
|
}
|
|
|
|
public async Task<IActionResult> Index()
|
|
{
|
|
var orders = await _orderService.GetAllOrdersAsync();
|
|
var products = await _productService.GetAllProductsAsync();
|
|
var categories = await _categoryService.GetAllCategoriesAsync();
|
|
|
|
// Basic metrics
|
|
ViewData["TotalOrders"] = orders.Count();
|
|
ViewData["TotalProducts"] = products.Count();
|
|
ViewData["TotalCategories"] = categories.Count();
|
|
ViewData["TotalRevenue"] = orders.Where(o => o.PaidAt.HasValue).Sum(o => o.TotalAmount).ToString("F2");
|
|
|
|
// Enhanced metrics
|
|
ViewData["TotalMultiBuys"] = products.Sum(p => p.MultiBuys.Count);
|
|
ViewData["TotalVariants"] = products.Sum(p => p.Variants.Count);
|
|
ViewData["PendingOrders"] = orders.Count(o => o.Status == LittleShop.Enums.OrderStatus.PendingPayment);
|
|
ViewData["ShippedOrders"] = orders.Count(o => o.Status == LittleShop.Enums.OrderStatus.Shipped);
|
|
ViewData["TotalStock"] = products.Sum(p => p.StockQuantity);
|
|
ViewData["LowStockProducts"] = products.Count(p => p.StockQuantity < 10);
|
|
ViewData["OutOfStockProducts"] = products.Count(p => p.StockQuantity == 0);
|
|
|
|
// Recent activity
|
|
ViewData["RecentOrders"] = orders.OrderByDescending(o => o.CreatedAt).Take(5);
|
|
ViewData["TopProducts"] = products.OrderByDescending(p => p.StockQuantity).Take(5);
|
|
|
|
// System information
|
|
ViewData["ConnectionString"] = _configuration.GetConnectionString("DefaultConnection") ?? "Not configured";
|
|
|
|
return View();
|
|
}
|
|
} |