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/IoTCenter/Areas/Admin/Controllers/GlobalSceneCommandControlle...

56 lines
2.3 KiB

using Application.Domain.Entities;
using Application.Models;
using Infrastructure.Application;
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Web.Mvc;
using IoT.Shared.Areas.Admin.Controlls;
using IoTCenter.Application.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System.Linq;
namespace IoTCenter.Areas.Admin.Controllers
{
[Authorize]
[Area(nameof(Admin))]
public class GlobalSceneCommandController : CrudController<SceneCommand, PagedListModel<EditGlobalSceneCommandModel>, EditGlobalSceneCommandModel, EditGlobalSceneCommandModel>
{
private readonly AjaxController _ajax;
public GlobalSceneCommandController(IRepository<SceneCommand> repo, AjaxController ajax) : base(repo)
{
this._ajax = ajax;
}
public override IQueryable<SceneCommand> Include(IQueryable<SceneCommand> query)
{
return query.Include(o => o.Scene).Include(o => o.Command).ThenInclude(o => o.Device).ThenInclude(o => o.Node);
}
public override IQueryable<SceneCommand> Query(PagedListModel<EditGlobalSceneCommandModel> model, IQueryable<SceneCommand> query)
{
return query.Where(o => o.Scene.Node == null).OrderBy(o => o.SceneId);
}
public override void ToEditModel(SceneCommand entity, EditGlobalSceneCommandModel model)
{
this.ToDisplayModel(entity, model);
ViewData.SelectList(o => model.SceneId, () => this._ajax.GetGlobalSceneSelectList(model.SceneId));
ViewData.SelectList(o => model.NodeId, () => this._ajax.GetNodeSelectList(model.NodeId));
ViewData.SelectList(o => model.CommandId, () => this._ajax.GetCommandSelectList(model.NodeId.Value, model.CommandId), model.NodeId.HasValue);
}
public override void ToDisplayModel(SceneCommand entity, EditGlobalSceneCommandModel model)
{
if (entity != null)
{
model.NodeId = entity.Command.Device.NodeId;
ViewData.Add(model.SceneId, entity.Scene.Name);
ViewData.Add(model.NodeId, entity.Command.Device.Node.Name);
ViewData.Add(model.CommandId, entity.Command.Name);
}
}
}
}