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.
56 lines
1.8 KiB
56 lines
1.8 KiB
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<TEntity, TEditModel> : CrudController<TEntity, TEditModel>
|
|
where TEntity : BaseEntity
|
|
where TEditModel : EditModel
|
|
{
|
|
protected readonly IServiceProvider applicationServices;
|
|
|
|
public IoTSharedController(IRepository<TEntity> 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<IHubContext<IoTCenterHub>>();
|
|
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();
|
|
}
|
|
}
|
|
}
|