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/IoTCenter/Areas/Admin/Controllers/GlobalIoTTimerController.cs

50 lines
1.7 KiB

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<IoTTimer, PagedListModel<EditGlobalIoTTimerModel>, EditGlobalIoTTimerModel, EditGlobalIoTTimerModel>
{
private readonly IServiceProvider _sp;
public GlobalIoTTimerController(IRepository<IoTTimer> repo, IServiceProvider sp) : base(repo)
{
this._sp = sp;
}
public override IQueryable<IoTTimer> Query(PagedListModel<EditGlobalIoTTimerModel> model, IQueryable<IoTTimer> 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<IEventPublisher>();
eventPublisher.Publish(new EntityUpdatedEvent<IoTTimer>(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<IEventPublisher>();
eventPublisher.Publish(new EntityDeletedEvent<IoTTimer>(entity));
}
}
}