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/IoT.Shared/Areas/Admin/Controlls/IoTTimerCommandController.cs

62 lines
2.6 KiB

using Application.Domain.Entities;
using Application.Models;
using Infrastructure.Application;
using Infrastructure.Data;
using Infrastructure.Extensions;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Linq;
namespace IoT.Shared.Areas.Admin.Controlls
{
[Authorize]
[Area(nameof(Admin))]
public class IoTTimerCommandController : SharedController<IoTTimerCommand, PagedListModel<EditIoTTimerCommandModel>, EditIoTTimerCommandModel, EditIoTTimerCommandModel>
{
private readonly IRepository<Node> _nodeRepo;
private readonly AjaxController _ajax;
public IoTTimerCommandController(IRepository<Node> nodeRepo, IRepository<IoTTimerCommand> repo, AjaxController ajax, IServiceProvider sp) : base(repo, sp)
{
this._nodeRepo = nodeRepo;
this._ajax = ajax;
}
public override IQueryable<IoTTimerCommand> Include(IQueryable<IoTTimerCommand> query)
{
return query.Include(o => o.IoTTimer).ThenInclude(o => o.Node)
.Include(o => o.Command).ThenInclude(o => o.Device);
}
public override IQueryable<IoTTimerCommand> Query(PagedListModel<EditIoTTimerCommandModel> model, IQueryable<IoTTimerCommand> query)
{
return query.Where(o => o.IoTTimer.NodeId != null);
}
public override void ToEditModel(IoTTimerCommand entity, EditIoTTimerCommandModel model)
{
this.ToDisplayModel(entity, model);
ViewData.SelectList(o => model.NodeId, () => this._ajax.GetNodeSelectList(model.IoTTimerId));
ViewData.SelectList(o => model.IoTTimerId, () => this._ajax.GetIoTTimerSelectList(model.NodeId.Value, model.IoTTimerId), model.NodeId.HasValue);
ViewData.SelectList(o => model.CommandId, () => this._ajax.GetCommandSelectList(model.NodeId.Value, model.CommandId), model.NodeId.HasValue);
}
public override void ToDisplayModel(IoTTimerCommand entity, EditIoTTimerCommandModel model)
{
if (entity != null)
{
model.NodeId = entity.IoTTimer.NodeId;
ViewData.Add(model.NodeId, entity.IoTTimer.Node.Name);
ViewData.Add(model.IoTTimerId, entity.IoTTimer.Name);
ViewData.Add(model.CommandId, entity.Command.Name);
}
}
public override string GetNodeNumber(EditIoTTimerCommandModel model)
{
return this._nodeRepo.ReadOnlyTable().Where(o => o.Id == model.NodeId).Select(o => o.Number).FirstOrDefault();
}
}
}