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/Controllers/HomeController.cs

113 lines
3.1 KiB

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<User> _userRepo;
private readonly IRepository<Area> _areaRepo;
private readonly IRepository<Organ> _organRepo;
private readonly IRepository<Building> _buildingRepo;
public HomeController(IUserService userService, IRepository<User> userRepo, IRepository<Area> areaRepo, IRepository<Organ> organRepo, IRepository<Building> buildingRepo)
{
this._useService = userService;
this._userRepo = userRepo;
this._areaRepo = areaRepo;
this._organRepo = organRepo;
this._buildingRepo = buildingRepo;
}
public IActionResult Index()
{
var area = this._areaRepo.ReadOnlyTable()
.Where(o => o.Name == "南关区")
.Include(o => o.Parent).ThenInclude(o => o.Parent).First();
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 organId = User.GetOrganId();
var organ = this._organRepo.ReadOnlyTable()
.WhereIf(organId.HasValue, o => o.Id == organId.Value)
.FirstOrDefault();
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.Id == organId.Value);
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))
};
}
}
}