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.
66 lines
2.4 KiB
66 lines
2.4 KiB
using Infrastructure.Data;
|
|
using Infrastructure.Web;
|
|
using IoT.Shared.Application.Domain.Entities;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Platform.Areas.IoTCenter.ViewModels;
|
|
using System.Linq;
|
|
|
|
namespace Platform.Areas.IoTCenter.Controllers
|
|
{
|
|
[Authorize]
|
|
[Area("IoTCenter")]
|
|
public class HomeController : BaseController
|
|
{
|
|
private readonly IRepository<IoTGateway> _nodeRepo;
|
|
private readonly IRepository<IoTProduct> _productRepo;
|
|
private readonly IRepository<IoTDevice> _deviceRepo;
|
|
private readonly IRepository<IoTProductCategory> _categoryRepo;
|
|
|
|
public HomeController(IRepository<IoTGateway> nodeRepo, IRepository<IoTProductCategory> categoryRepo, IRepository<IoTProduct> productRepo, IRepository<IoTDevice> deviceRepo)
|
|
{
|
|
this._nodeRepo = nodeRepo;
|
|
this._categoryRepo = categoryRepo;
|
|
this._productRepo = productRepo;
|
|
this._deviceRepo = deviceRepo;
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
var model = new HomeIndexViewModel
|
|
{
|
|
Nodes = this._nodeRepo.ReadOnlyTable()
|
|
.ToList()
|
|
.Select(o => new NodeViewModel
|
|
{
|
|
Id = o.Id,
|
|
Number = o.Number,
|
|
Name = o.Name,
|
|
Image = o.Image,
|
|
DeviceCount = _deviceRepo.ReadOnlyTable().Count(d => d.NodeId == o.Id)
|
|
}).ToList(),
|
|
Categories = this._categoryRepo.ReadOnlyTable()
|
|
.ToList()
|
|
.Select(o => new CategoryViewModel
|
|
{
|
|
Id = o.Id,
|
|
Name = o.Name,
|
|
Image = o.Image,
|
|
Number = o.Number,
|
|
DeviceCount = _deviceRepo.ReadOnlyTable().Count(d => d.Product.CategoryId == o.Id)
|
|
}).ToList(),
|
|
Products = this._productRepo.ReadOnlyTable()
|
|
.ToList()
|
|
.Select(o => new ProductViewModel
|
|
{
|
|
Id = o.Id,
|
|
Name = o.Name,
|
|
Image = o.Image,
|
|
DeviceCount = _deviceRepo.ReadOnlyTable().Count(d => d.ProductId == o.Id)
|
|
}).ToList()
|
|
};
|
|
return this.Result<ProductViewModel>(model);
|
|
}
|
|
}
|
|
}
|