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.
55 lines
2.3 KiB
55 lines
2.3 KiB
using Application.Domain.Entities;
|
|
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 GlobalIoTTimerCommandController : CrudController<IoTTimerCommand, PagedListModel<EditGlobalIoTTimerCommandModel>, EditGlobalIoTTimerCommandModel, EditGlobalIoTTimerCommandModel>
|
|
{
|
|
private readonly AjaxController _ajax;
|
|
|
|
public GlobalIoTTimerCommandController(IRepository<IoTTimerCommand> repo, AjaxController ajax) : base(repo)
|
|
{
|
|
this._ajax = ajax;
|
|
}
|
|
|
|
public override IQueryable<IoTTimerCommand> Include(IQueryable<IoTTimerCommand> query)
|
|
{
|
|
return query.Include(o => o.IoTTimer).Include(o => o.Command).ThenInclude(o => o.Device).ThenInclude(o => o.Node);
|
|
}
|
|
|
|
public override IQueryable<IoTTimerCommand> Query(PagedListModel<EditGlobalIoTTimerCommandModel> model, IQueryable<IoTTimerCommand> query)
|
|
{
|
|
return query.Where(o => o.IoTTimer.Node == null);
|
|
}
|
|
|
|
public override void ToEditModel(IoTTimerCommand entity, EditGlobalIoTTimerCommandModel model)
|
|
{
|
|
this.ToDisplayModel(entity, model);
|
|
ViewData.SelectList(o => model.IoTTimerId, () => this._ajax.GetGlobalIoTTimerSelectList(model.IoTTimerId));
|
|
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(IoTTimerCommand entity, EditGlobalIoTTimerCommandModel model)
|
|
{
|
|
if (entity != null)
|
|
{
|
|
model.NodeId = entity.Command.Device.NodeId;
|
|
ViewData.Add(model.NodeId, entity.Command.Device.Node.Name);
|
|
ViewData.Add(model.IoTTimerId, entity.IoTTimer.Name);
|
|
ViewData.Add(model.CommandId, entity.Command.Name);
|
|
}
|
|
}
|
|
}
|
|
} |