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.
58 lines
1.9 KiB
58 lines
1.9 KiB
using System;
|
|
using System.Linq;
|
|
using Application.Domain.Entities;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Jwt;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace IoTCenter.Controllers
|
|
{
|
|
public class HomeController : Controller
|
|
{
|
|
private readonly IJwtHelper _jwtHelper;
|
|
private readonly IRepository<Node> _nodeRepo;
|
|
private readonly IRepository<Device> _deviceRepo;
|
|
|
|
public HomeController(IJwtHelper jwtHelper, IRepository<Node> nodeRepo, IRepository<Device> deviceRepo)
|
|
{
|
|
this._jwtHelper = jwtHelper;
|
|
this._nodeRepo = nodeRepo;
|
|
this._deviceRepo = deviceRepo;
|
|
}
|
|
|
|
[Authorize]
|
|
public IActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
public IActionResult GetNodes(string token)
|
|
{
|
|
var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString();
|
|
var model = this._nodeRepo.ReadOnlyTable()
|
|
.Select(o => new { o.Number, o.Name, o.DisplayOrder, Count = o.Devices.Count })
|
|
.ToList();
|
|
return Json(model);
|
|
}
|
|
|
|
[Authorize]
|
|
public IActionResult Node(Guid id)
|
|
{
|
|
var model = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == id);
|
|
return View(model);
|
|
}
|
|
|
|
public IActionResult GetNode(Guid id)
|
|
{
|
|
var model = this._nodeRepo.ReadOnlyTable()
|
|
.Include(o => o.Sences)
|
|
.Include(o => o.Devices).ThenInclude(o => o.Data)
|
|
.Include(o => o.Devices).ThenInclude(o => o.Apis).ThenInclude(o => o.Parameters)
|
|
.FirstOrDefault(o => o.Id == id);
|
|
return Json(model, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
|
|
}
|
|
}
|
|
} |