38 lines
1.2 KiB
C#
38 lines
1.2 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;
|
|
|
|
public DashboardController(
|
|
IOrderService orderService,
|
|
IProductService productService,
|
|
ICategoryService categoryService)
|
|
{
|
|
_orderService = orderService;
|
|
_productService = productService;
|
|
_categoryService = categoryService;
|
|
}
|
|
|
|
public async Task<IActionResult> 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();
|
|
}
|
|
} |