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.
76 lines
3.7 KiB
76 lines
3.7 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;
|
|
using System.Linq;
|
|
|
|
namespace Platform.Areas.IoTCenter.Controllers
|
|
{
|
|
[Authorize]
|
|
[ApiController]
|
|
[Route("IoTCenter/[controller]/[action]")]
|
|
[Area("IoTCenter")]
|
|
[ControllerScope(ControllerScopeType.Platform)]
|
|
|
|
public class IoTTiggerController : CrudController<IoTTigger, EditIoTTiggerModel>
|
|
{
|
|
private readonly AjaxController _ajax;
|
|
private readonly IServiceProvider _sp;
|
|
|
|
public IoTTiggerController(IRepository<IoTTigger> repo, AjaxController ajax, IServiceProvider sp) : base(repo)
|
|
{
|
|
this._ajax = ajax;
|
|
this._sp = sp;
|
|
}
|
|
|
|
public override IQueryable<IoTTigger> Include(IQueryable<IoTTigger> query)
|
|
{
|
|
return query
|
|
.Include(o => o.IoTScene)
|
|
.Include(o => o.Data).ThenInclude(o => o.Device).ThenInclude(o => o.IoTGateway);
|
|
}
|
|
|
|
public override IQueryable<IoTTigger> Query(PagedListModel<EditIoTTiggerModel> model, IQueryable<IoTTigger> query)
|
|
{
|
|
return query
|
|
.WhereIf(model.Query.OrganId.HasValue, o => o.IoTScene.Building.OrganId == model.Query.OrganId.Value)
|
|
.WhereIf(model.Query.IoTGatewayId.HasValue, o => o.Data.Device.IoTGatewayId == model.Query.IoTGatewayId.Value)
|
|
.WhereIf(model.Query.OrganSceneId.HasValue, o => o.IoTSceneId == model.Query.OrganSceneId.Value)
|
|
.WhereIf(model.Query.DeviceId.HasValue, o => o.Data.DeviceId == model.Query.DeviceId.Value)
|
|
.WhereIf(model.Query.DataId.HasValue, o => o.DataId == model.Query.DataId.Value)
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Condition), o => o.Condition.Contains(model.Query.Condition))
|
|
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
|
|
.WhereIf(model.Query.Disabled.HasValue, o => o.Disabled == model.Query.Disabled.Value)
|
|
.OrderBy(o => o.IoTSceneId);
|
|
}
|
|
|
|
public override void ToEditModel(IoTTigger entity, EditIoTTiggerModel model)
|
|
{
|
|
this.ToDisplayModel(entity, model);
|
|
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrgan(model.OrganId).SelectList());
|
|
ViewData.SelectList(o => model.IoTGatewayId, () => this._ajax.GetIoTGateway(model.IoTGatewayId).SelectList(), model.OrganId.HasValue);
|
|
ViewData.SelectList(o => model.OrganSceneId, () => this._ajax.GetOrganSceneSelectList(model.OrganId.Value, model.OrganSceneId), model.OrganId.HasValue);
|
|
ViewData.SelectList(o => model.DeviceId, () => this._ajax.GetIoTDevice(model.IoTGatewayId.Value, model.DeviceId).SelectList(), model.IoTGatewayId.HasValue);
|
|
ViewData.SelectList(o => model.DataId, () => this._ajax.GetDataSelectList(model.DeviceId.Value), model.DeviceId.HasValue);
|
|
}
|
|
|
|
public override void ToDisplayModel(IoTTigger entity, EditIoTTiggerModel model)
|
|
{
|
|
model.OrganId = entity?.IoTScene?.Building?.OrganId;
|
|
model.DeviceId = entity?.Data?.DeviceId;
|
|
model.IoTGatewayId = entity?.Data?.Device?.IoTGatewayId;
|
|
ViewData.Add(model.IoTGatewayId, entity?.Data?.Device?.IoTGateway?.Name);
|
|
ViewData.Add(model.OrganSceneId, entity?.IoTScene?.Name);
|
|
ViewData.Add(model.DataId, entity?.Data?.Name);
|
|
ViewData.Add(model.DeviceId, entity?.Data?.Device?.DisplayName);
|
|
}
|
|
}
|
|
}
|