using Infrastructure.Application; using Infrastructure.Data; using Infrastructure.Domain; using Infrastructure.Extensions; using Infrastructure.Web.Mvc; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.DependencyInjection; using Platform.Services; using System; namespace IoT.Shared.Areas.IoTCenter.Controlls { public class IoTSharedController : CrudController where TEntity : BaseEntity where TEditModel : EditModel { protected readonly IServiceProvider applicationServices; public IoTSharedController(IRepository repo, IServiceProvider applicationServices) : base(repo) { this.applicationServices = applicationServices; } public override IActionResult Edit(TEditModel model) { if (ModelState.IsValid) { try { var method = $"Edit{typeof(TEntity).Name}"; using var scope = this.applicationServices.CreateScope(); var group = this.GetNodeNumber(model); this.ToEntity(model, null); var hub = scope.ServiceProvider.GetService>(); hub.ServerToClient(method, model, group); return Success(); } catch (Exception ex) { ex.PrintStack(); ModelState.AddModelError("", ex.Message); } } this.ToEditModel(null, model); return Result(model); } [ApiExplorerSettings(IgnoreApi = true)] public virtual string GetNodeNumber(TEditModel model) { throw new NotImplementedException(); } } }