|
|
@ -13,41 +13,49 @@ namespace IoTCenter.Areas.Admin.Controllers
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly IRepository<Node> _nodeRepo;
|
|
|
|
private readonly IRepository<Node> _nodeRepo;
|
|
|
|
private readonly IRepository<Product> _productRepo;
|
|
|
|
private readonly IRepository<Product> _productRepo;
|
|
|
|
|
|
|
|
private readonly IRepository<Device> _deviceRepo;
|
|
|
|
private readonly IRepository<Category> _categoryRepo;
|
|
|
|
private readonly IRepository<Category> _categoryRepo;
|
|
|
|
|
|
|
|
|
|
|
|
public HomeController(IRepository<Node> nodeRepo, IRepository<Category> categoryRepo, IRepository<Product> productRepo)
|
|
|
|
public HomeController(IRepository<Node> nodeRepo, IRepository<Category> categoryRepo, IRepository<Product> productRepo, IRepository<Device> deviceRepo)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this._nodeRepo = nodeRepo;
|
|
|
|
this._nodeRepo = nodeRepo;
|
|
|
|
this._categoryRepo = categoryRepo;
|
|
|
|
this._categoryRepo = categoryRepo;
|
|
|
|
this._productRepo = productRepo;
|
|
|
|
this._productRepo = productRepo;
|
|
|
|
|
|
|
|
this._deviceRepo = deviceRepo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IActionResult Index()
|
|
|
|
public IActionResult Index()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var model = new HomeIndexViewModel
|
|
|
|
var model = new HomeIndexViewModel
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Nodes = this._nodeRepo.ReadOnlyTable().Select(o => new NodeViewModel
|
|
|
|
Nodes = this._nodeRepo.ReadOnlyTable()
|
|
|
|
|
|
|
|
.ToList()
|
|
|
|
|
|
|
|
.Select(o => new NodeViewModel
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Id = o.Id,
|
|
|
|
Id = o.Id,
|
|
|
|
Number = o.Number,
|
|
|
|
Number = o.Number,
|
|
|
|
Name = o.Name,
|
|
|
|
Name = o.Name,
|
|
|
|
Image = o.Image,
|
|
|
|
Image = o.Image,
|
|
|
|
DeviceCount = o.Devices.Count()
|
|
|
|
DeviceCount = _deviceRepo.ReadOnlyTable().Count(d => d.NodeId == o.Id)
|
|
|
|
}).ToList(),
|
|
|
|
}).ToList(),
|
|
|
|
Categories = this._categoryRepo.ReadOnlyTable().Select(o => new CategoryViewModel
|
|
|
|
Categories = this._categoryRepo.ReadOnlyTable()
|
|
|
|
|
|
|
|
.ToList()
|
|
|
|
|
|
|
|
.Select(o => new CategoryViewModel
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Id = o.Id,
|
|
|
|
Id = o.Id,
|
|
|
|
Name = o.Name,
|
|
|
|
Name = o.Name,
|
|
|
|
Image = o.Image,
|
|
|
|
Image = o.Image,
|
|
|
|
Number = o.Number,
|
|
|
|
Number = o.Number,
|
|
|
|
DeviceCount = o.Products.SelectMany(o => o.Devices).Count()
|
|
|
|
DeviceCount = _deviceRepo.ReadOnlyTable().Count(d => d.Product.CategoryId == o.Id)
|
|
|
|
}).ToList(),
|
|
|
|
}).ToList(),
|
|
|
|
Products = this._productRepo.ReadOnlyTable().Select(o => new ProductViewModel
|
|
|
|
Products = this._productRepo.ReadOnlyTable()
|
|
|
|
|
|
|
|
.ToList()
|
|
|
|
|
|
|
|
.Select(o => new ProductViewModel
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Id = o.Id,
|
|
|
|
Id = o.Id,
|
|
|
|
Name = o.Name,
|
|
|
|
Name = o.Name,
|
|
|
|
Image = o.Image,
|
|
|
|
Image = o.Image,
|
|
|
|
DeviceCount = o.Devices.Count()
|
|
|
|
DeviceCount = _deviceRepo.ReadOnlyTable().Count(d => d.ProductId == o.Id)
|
|
|
|
}).ToList()
|
|
|
|
}).ToList()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return View(model);
|
|
|
|
return View(model);
|
|
|
|