using Application.Domain.Entities; using Infrastructure.Application; using Infrastructure.Data; using Infrastructure.Events; using Infrastructure.Web.Mvc; using IoTCenter.Application.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using System; using System.Linq; namespace IoTCenter.Areas.Admin.Controllers { [Authorize] [Area(nameof(Admin))] public class GlobalIoTTimerController : CrudController, EditGlobalIoTTimerModel, EditGlobalIoTTimerModel> { private readonly IServiceProvider _sp; public GlobalIoTTimerController(IRepository repo, IServiceProvider sp) : base(repo) { this._sp = sp; } public override IQueryable Query(PagedListModel model, IQueryable query) { return query.Where(o => o.NodeId == null); } public override void OnInserted(IoTTimer entity) { using var scope = this._sp.CreateScope(); var eventPublisher = scope.ServiceProvider.GetService(); eventPublisher.Publish(new EntityUpdatedEvent(entity)); } public override void OnUpdated(IoTTimer entity) { this.OnInserted(entity); } public override void OnDeleted(IoTTimer entity) { using var scope = this._sp.CreateScope(); var eventPublisher = scope.ServiceProvider.GetService(); eventPublisher.Publish(new EntityDeletedEvent(entity)); } } }