| 1 | using Microsoft.AspNetCore.Mvc;
|
|---|
| 2 | using StockMaster.Services;
|
|---|
| 3 | using StockMaster.ViewModels;
|
|---|
| 4 | using System;
|
|---|
| 5 | using System.Threading.Tasks;
|
|---|
| 6 |
|
|---|
| 7 | namespace StockMaster.Controllers
|
|---|
| 8 | {
|
|---|
| 9 | public class HomeController : BaseController
|
|---|
| 10 | {
|
|---|
| 11 | private readonly IProductService _productService;
|
|---|
| 12 | private readonly ISaleService _saleService;
|
|---|
| 13 | private readonly IWarehouseService _warehouseService;
|
|---|
| 14 |
|
|---|
| 15 | public HomeController(
|
|---|
| 16 | IProductService productService,
|
|---|
| 17 | ISaleService saleService,
|
|---|
| 18 | IWarehouseService warehouseService)
|
|---|
| 19 | {
|
|---|
| 20 | _productService = productService;
|
|---|
| 21 | _saleService = saleService;
|
|---|
| 22 | _warehouseService = warehouseService;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | public async Task<IActionResult> Index()
|
|---|
| 26 | {
|
|---|
| 27 | var viewModel = new DashboardViewModel
|
|---|
| 28 | {
|
|---|
| 29 | LowStockProducts = await _productService.GetLowStockProductsAsync(),
|
|---|
| 30 | TotalSalesToday = await _saleService.GetTotalSalesAmountAsync(
|
|---|
| 31 | DateTime.Today,
|
|---|
| 32 | DateTime.Today.AddDays(1)),
|
|---|
| 33 | TotalSalesMonth = await _saleService.GetTotalSalesAmountAsync(
|
|---|
| 34 | new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1)),
|
|---|
| 35 | StockSummary = await _warehouseService.GetStockSummaryAsync()
|
|---|
| 36 | };
|
|---|
| 37 |
|
|---|
| 38 | return View(viewModel);
|
|---|
| 39 | }
|
|---|
| 40 | }
|
|---|
| 41 | } |
|---|