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.
89 lines
3.6 KiB
89 lines
3.6 KiB
using Infrastructure.Application;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Web.Mvc;
|
|
using Application.Domain.Entities;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Platform.Application.Models;
|
|
using System.Linq;
|
|
|
|
namespace Platform.Areas.IoTCenter.Controllers
|
|
{
|
|
[Authorize]
|
|
[ApiController]
|
|
[Route("IoTCenter/[controller]/[action]")]
|
|
[Area("IoTCenter")]
|
|
[ControllerScope(ControllerScopeType.Platform)]
|
|
public class IoTSceneController : CrudController<IoTScene, EditIoTSceneModel>
|
|
{
|
|
private readonly AjaxController _ajax;
|
|
|
|
private readonly IRepository<Organ> _organRepo;
|
|
|
|
private readonly IRepository<Building> _buildingRepo;
|
|
|
|
public IoTSceneController(IRepository<IoTScene> repo,
|
|
AjaxController ajax,
|
|
IRepository<Organ> organRepo,
|
|
IRepository<Building> buildingRepo) : base(repo)
|
|
{
|
|
this._ajax = ajax;
|
|
this._organRepo = organRepo;
|
|
this._buildingRepo = buildingRepo;
|
|
}
|
|
|
|
public override IQueryable<IoTScene> Include(IQueryable<IoTScene> query)
|
|
{
|
|
return query.Include(o => o.Building).ThenInclude(o => o.Organ);
|
|
}
|
|
|
|
public override IQueryable<IoTScene> Query(PagedListModel<EditIoTSceneModel> model, IQueryable<IoTScene> query)
|
|
{
|
|
ViewData.SelectList(o => model.Query.OrganId, () => this._ajax.GetOrgan(model.Query.OrganId).SelectList());
|
|
return query
|
|
.WhereIf(model.Query.OrganId.HasValue, o => o.Building.OrganId == model.Query.OrganId.Value)
|
|
.WhereIf(model.Query.BuildingId.HasValue, o => o.BuildingId == model.Query.BuildingId.Value)
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
|
|
.WhereIf(model.Query.Hidden.HasValue, o => o.Hidden == model.Query.Hidden.Value)
|
|
.OrderBy(o => o.Order);
|
|
}
|
|
|
|
public override void EntityToModel(IoTScene entity, EditIoTSceneModel model)
|
|
{
|
|
model.OrganId = entity.Building.OrganId;
|
|
}
|
|
|
|
public override void ToDisplayModel(IoTScene entity, EditIoTSceneModel model)
|
|
{
|
|
if (model.BuildingId.HasValue)
|
|
{
|
|
var name = this._buildingRepo.ReadOnlyTable()
|
|
.Where(o => o.ParentId != null)
|
|
.Where(o => o.Left <= entity.Building.Left && o.Right >= entity.Building.Right)
|
|
.ToList()
|
|
.ToTree()
|
|
.FirstOrDefault(o => o.Id == model.BuildingId.Value)?.GetDisplayName();
|
|
ViewData.Add(model.BuildingId.Value, name);
|
|
}
|
|
if (model.OrganId.HasValue)
|
|
{
|
|
var name = this._organRepo.ReadOnlyTable()
|
|
.Where(o => o.ParentId != null)
|
|
.Where(o => o.Left <= entity.Building.Organ.Left && o.Right >= entity.Building.Organ.Right)
|
|
.ToList()
|
|
.ToTree()
|
|
.FirstOrDefault(o => o.Id == entity.Building.OrganId)?.GetDisplayName();
|
|
ViewData.Add(model.OrganId, name);
|
|
}
|
|
}
|
|
|
|
public override void ToEditModel(IoTScene entity, EditIoTSceneModel model)
|
|
{
|
|
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList());
|
|
ViewData.SelectList(o => model.BuildingId, () => this._ajax.GetBuilding(model.OrganId.Value, model.BuildingId).SelectList(), model.OrganId.HasValue);
|
|
}
|
|
}
|
|
}
|