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; public DashboardController( IOrderService orderService, IProductService productService, ICategoryService categoryService) { _orderService = orderService; _productService = productService; _categoryService = categoryService; } public async Task Index() { var orders = await _orderService.GetAllOrdersAsync(); var products = await _productService.GetAllProductsAsync(); var categories = await _categoryService.GetAllCategoriesAsync(); ViewData["TotalOrders"] = orders.Count(); ViewData["TotalProducts"] = products.Count(); ViewData["TotalCategories"] = categories.Count(); ViewData["TotalRevenue"] = orders.Where(o => o.PaidAt.HasValue).Sum(o => o.TotalAmount); return View(); } }