using Infrastructure.Data; using Infrastructure.Extensions; using Infrastructure.Web; using IoT.Shared.Application.Domain.Entities; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Platform.ViewModels; using System.Linq; namespace Platform.Controllers { [Authorize] //[Device] [ApiExplorerSettings(IgnoreApi = true)] public class HomeController : BaseController { private readonly IUserService _useService; private readonly IRepository _userRepo; private readonly IRepository _organRepo; private readonly IRepository _buildingRepo; public HomeController(IUserService userService, IRepository userRepo, IRepository organRepo, IRepository buildingRepo) { this._useService = userService; this._userRepo = userRepo; this._organRepo = organRepo; this._buildingRepo = buildingRepo; } public IActionResult Index() { return View(); } public IActionResult Product() { return View(); } public IActionResult Device() { return View(); } public IActionResult Organ() { return View(); } public IActionResult Nodes() { return View(); } public IActionResult Node() { return View(); } public string Mac(string id) { return Helper.Instance.MacEncrypt(id); } public IActionResult Index2(HomeModel model) { var currentOrganNumber = User.GetUserData(); var organ = this._organRepo.ReadOnlyTable() .FirstOrDefault(o => o.Number == currentOrganNumber); var children = this._organRepo.Table() .Where(o => o.Left >= organ.Left && o.Right <= organ.Right) .Include(o => o.Buildings) .ToList(); var root = children.FirstOrDefault(o => o.Number == currentOrganNumber); model.Organ = root; if (string.IsNullOrEmpty(model.OrganNumber)) { model.OrganNumber = root.Number; } return View(model); } public IActionResult Index3() { return View(); } public IActionResult Index4() { return View(); } private object Convert(Organ root) { return new { title = root.Name, key = root.Number, children = root.Children.Select(o => Convert(o)) }; } } }