You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.9 KiB
55 lines
1.9 KiB
using Application.Domain.Entities;
|
|
using Infrastructure.Data;
|
|
using IoTCenter.Areas.Admin.ViewModels;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Linq;
|
|
|
|
namespace IoTCenter.Areas.Admin.Controllers
|
|
{
|
|
[Authorize]
|
|
[Area(nameof(Admin))]
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly IRepository<Node> _nodeRepo;
|
|
private readonly IRepository<Product> _productRepo;
|
|
private readonly IRepository<Category> _categoryRepo;
|
|
|
|
public HomeController(IRepository<Node> nodeRepo, IRepository<Category> categoryRepo, IRepository<Product> productRepo)
|
|
{
|
|
this._nodeRepo = nodeRepo;
|
|
this._categoryRepo = categoryRepo;
|
|
this._productRepo = productRepo;
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
var model = new HomeIndexViewModel
|
|
{
|
|
Nodes = this._nodeRepo.ReadOnlyTable().Select(o => new NodeViewModel
|
|
{
|
|
Id = o.Id,
|
|
Name = o.Name,
|
|
Image = o.Image,
|
|
DeviceCount = o.Devices.Count()
|
|
}).ToList(),
|
|
Categories = this._categoryRepo.ReadOnlyTable().Select(o => new CategoryViewModel
|
|
{
|
|
Id = o.Id,
|
|
Name = o.Name,
|
|
Image = o.Image,
|
|
Number = o.Number,
|
|
DeviceCount = o.Products.SelectMany(o => o.Devices).Count()
|
|
}).ToList(),
|
|
Products = this._productRepo.ReadOnlyTable().Select(o => new ProductViewModel
|
|
{
|
|
Id = o.Id,
|
|
Name = o.Name,
|
|
Image = o.Image,
|
|
DeviceCount = o.Devices.Count()
|
|
}).ToList()
|
|
};
|
|
return View(model);
|
|
}
|
|
}
|
|
} |