using Application.Domain.Entities; using Application.Models; using Infrastructure.Application; using Infrastructure.Data; using Infrastructure.Extensions; using Infrastructure.Web.Mvc; using IoTShared.Controllers; 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, EditSceneCommandModel, EditSceneCommandModel> { private readonly AjaxController _ajax; public GlobalSceneCommandController(IRepository repo, AjaxController ajax) : base(repo) { this._ajax = ajax; } public override IQueryable Include(IQueryable query) { return query.Include(o => o.Scene).ThenInclude(o => o.Node).Include(o => o.Command).ThenInclude(o => o.Device); } public override void ToModel(SceneCommand entity, EditSceneCommandModel model) { ViewData.SelectList(o => model.SceneId, () => this._ajax.GetGlobalSceneSelectList(model.SceneId)); ViewData.SelectList(o => model.NodeId, () => this._ajax.GetNodeSelectList(model.SceneId)); ViewData.SelectList(o => model.CommandId, () => this._ajax.GetCommandSelectList(model.NodeId.Value, model.CommandId), model.NodeId.HasValue); } } }