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.
iot/projects/Platform/Areas/IoTCenter/Controllers/HomeController.cs

65 lines
2.3 KiB

using Infrastructure.Data;
using Infrastructure.Web;
using 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.IoTGatewayId == o.Id)
}).ToList(),
Categories = this._categoryRepo.ReadOnlyTable()
.ToList()
.Select(o => new CategoryViewModel
{
Id = o.Id,
Name = o.Name,
Image = o.Image,
Number = o.Number
}).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.IoTProductId == o.Id)
}).ToList()
};
return this.Result<ProductViewModel>(model);
}
}
}