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.
65 lines
3.1 KiB
65 lines
3.1 KiB
using Infrastructure.Application;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Infrastructure.Web.Mvc;
|
|
using IoT.Shared.Application.Domain.Entities;
|
|
using IoT.Shared.Areas.IoTCenter.Controlls;
|
|
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 IoTSceneIoTCommandController : CrudController<IoTSceneIoTCommand, EditIoTSceneIoTCommandModel>
|
|
{
|
|
private readonly AjaxController _ajax;
|
|
|
|
public IoTSceneIoTCommandController(IRepository<IoTSceneIoTCommand> repo, AjaxController ajax) : base(repo)
|
|
{
|
|
this._ajax = ajax;
|
|
}
|
|
|
|
public override IQueryable<IoTSceneIoTCommand> Include(IQueryable<IoTSceneIoTCommand> query)
|
|
{
|
|
return query
|
|
.Include(o => o.IoTScene).ThenInclude(o=>o.Building).ThenInclude(o => o.Organ)
|
|
.Include(o => o.IoTCommand).ThenInclude(o => o.Device).ThenInclude(o => o.IoTGateway);
|
|
}
|
|
|
|
public override IQueryable<IoTSceneIoTCommand> Query(PagedListModel<EditIoTSceneIoTCommandModel> model, IQueryable<IoTSceneIoTCommand> query)
|
|
{
|
|
return query.WhereIf(model.Query.IoTGatewayId.HasValue, o => o.IoTCommand.Device.IoTGatewayId == model.Query.IoTGatewayId.Value)
|
|
.WhereIf(model.Query.IoTSceneId.HasValue, o => o.IoTSceneId == model.Query.IoTSceneId.Value)
|
|
.WhereIf(model.Query.CommandId.HasValue, o => o.IoTCommandId == model.Query.CommandId.Value)
|
|
.OrderBy(o => o.IoTSceneId);
|
|
}
|
|
|
|
public override void ToEditModel(IoTSceneIoTCommand entity, EditIoTSceneIoTCommandModel model)
|
|
{
|
|
this.ToDisplayModel(entity, model);
|
|
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList());
|
|
ViewData.SelectList(o => model.IoTSceneId, () => this._ajax.GetOrganSceneSelectList(model.OrganId.Value, model.IoTSceneId), model.OrganId.HasValue);
|
|
ViewData.SelectList(o => model.IoTGatewayId, () => this._ajax.GetOrganNodeSelectList(model.OrganId.Value, model.IoTGatewayId), model.OrganId.HasValue);
|
|
//ViewData.SelectList(o => model.CommandId, () => this._ajax.GetCommandSelectList(model.NodeId.Value, model.CommandId), model.NodeId.HasValue);
|
|
}
|
|
|
|
public override void ToDisplayModel(IoTSceneIoTCommand entity, EditIoTSceneIoTCommandModel model)
|
|
{
|
|
model.OrganId = entity?.IoTScene?.Building?.OrganId;
|
|
model.IoTGatewayId = entity?.IoTCommand.Device.IoTGatewayId;
|
|
ViewData.Add(model.OrganId, entity?.IoTScene?.Building?.Organ?.Name);
|
|
ViewData.Add(model.IoTSceneId, entity?.IoTScene?.Name);
|
|
ViewData.Add(model.IoTGatewayId, entity?.IoTCommand?.Device?.IoTGateway?.Name);
|
|
ViewData.Add(model.CommandId, entity?.IoTCommand?.Name);
|
|
}
|
|
}
|
|
}
|