Major restructuring of product variations: - Renamed ProductVariation to ProductMultiBuy for quantity-based pricing (e.g., "3 for £25") - Added new ProductVariant model for string-based options (colors, flavors) - Complete separation of multi-buy pricing from variant selection Features implemented: - Multi-buy deals with automatic price-per-unit calculation - Product variants for colors/flavors/sizes with stock tracking - TeleBot checkout supports both multi-buys and variant selection - Shopping cart correctly calculates multi-buy bundle prices - Order system tracks selected variants and multi-buy choices - Real-time bot activity monitoring with SignalR - Public bot directory page with QR codes for Telegram launch - Admin dashboard shows multi-buy and variant metrics Technical changes: - Updated all DTOs, services, and controllers - Fixed cart total calculation for multi-buy bundles - Comprehensive test coverage for new functionality - All existing tests passing with new features Database changes: - Migrated ProductVariations to ProductMultiBuys - Added ProductVariants table - Updated OrderItems to track variants 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
52 lines
2.1 KiB
C#
52 lines
2.1 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();
|
|
|
|
// 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);
|
|
|
|
return View();
|
|
}
|
|
} |