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.0 KiB
65 lines
3.0 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 OrganSceneCommandController : CrudController<OrganIoTSceneIoTCommand, EditOrganSceneCommandModel>
|
|
{
|
|
private readonly AjaxController _ajax;
|
|
|
|
public OrganSceneCommandController(IRepository<OrganIoTSceneIoTCommand> repo, AjaxController ajax) : base(repo)
|
|
{
|
|
this._ajax = ajax;
|
|
}
|
|
|
|
public override IQueryable<OrganIoTSceneIoTCommand> Include(IQueryable<OrganIoTSceneIoTCommand> query)
|
|
{
|
|
return query
|
|
.Include(o => o.OrganScene).ThenInclude(o => o.Organ)
|
|
.Include(o => o.Command).ThenInclude(o => o.Device).ThenInclude(o => o.Node);
|
|
}
|
|
|
|
public override IQueryable<OrganIoTSceneIoTCommand> Query(PagedListModel<EditOrganSceneCommandModel> model, IQueryable<OrganIoTSceneIoTCommand> query)
|
|
{
|
|
return query.WhereIf(model.Query.NodeId.HasValue, o => o.Command.Device.NodeId == model.Query.NodeId.Value)
|
|
.WhereIf(model.Query.OrganSceneId.HasValue, o => o.OrganSceneId == model.Query.OrganSceneId.Value)
|
|
.WhereIf(model.Query.CommandId.HasValue, o => o.CommandId == model.Query.CommandId.Value)
|
|
.OrderBy(o => o.OrganSceneId);
|
|
}
|
|
|
|
public override void ToEditModel(OrganIoTSceneIoTCommand entity, EditOrganSceneCommandModel model)
|
|
{
|
|
this.ToDisplayModel(entity, model);
|
|
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList());
|
|
ViewData.SelectList(o => model.OrganSceneId, () => this._ajax.GetOrganSceneSelectList(model.OrganId.Value, model.OrganSceneId), model.OrganId.HasValue);
|
|
ViewData.SelectList(o => model.NodeId, () => this._ajax.GetOrganNodeSelectList(model.OrganId.Value, model.NodeId), model.OrganId.HasValue);
|
|
//ViewData.SelectList(o => model.CommandId, () => this._ajax.GetCommandSelectList(model.NodeId.Value, model.CommandId), model.NodeId.HasValue);
|
|
}
|
|
|
|
public override void ToDisplayModel(OrganIoTSceneIoTCommand entity, EditOrganSceneCommandModel model)
|
|
{
|
|
model.OrganId = entity?.OrganScene.OrganId;
|
|
model.NodeId = entity?.Command.Device.NodeId;
|
|
ViewData.Add(model.OrganId, entity?.OrganScene?.Organ?.Name);
|
|
ViewData.Add(model.OrganSceneId, entity?.OrganScene?.Name);
|
|
ViewData.Add(model.NodeId, entity?.Command?.Device?.Node?.Name);
|
|
ViewData.Add(model.CommandId, entity?.Command?.Name);
|
|
}
|
|
}
|
|
}
|