using System; using System.Collections.Generic; using System.Linq; using Application.Domain.Entities; using Application.Models; using Application.Services; using Infrastructure.Application; using Infrastructure.Data; using Infrastructure.Web.Mvc; using IoTShared; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; namespace IoTCenter.Areas.Admin.Controllers { [Authorize] [Area(nameof(Admin))] public class NodeController : CrudController, EditNodeModel, EditNodeModel> { private readonly IRepository _repo; private readonly IHubContext _pageHubContext; private readonly INodeService _nodeService; public NodeController(IRepository repo, IHubContext pageHubContext, INodeService nodeService) : base(repo) { this._repo = repo; this._pageHubContext = pageHubContext; this._nodeService = nodeService; } public override IActionResult Edit(EditNodeModel model) { if (ModelState.IsValid) { this._pageHubContext.Clients.Group(model.Number).SendAsync(nameof(INodeService.EditNode), model); return RedirectTo(); } ModelState.AddModelError("", "服务器出现异常,请稍后重试"); return View(model); } public override IActionResult Delete(List list) { foreach (var id in list) { var model = this._repo.ReadOnlyTable().FirstOrDefault(o => o.Id == id); this._pageHubContext.Clients.Group(model.Number).SendAsync(nameof(INodeService.DeleteNode), id); } return RedirectTo(); } } }