forked from ddrilling/AsbCloudServer
39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Services;
|
|
using AsbCloudDb.Model;
|
|
using AsbCloudInfrastructure.Services.Cache;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace AsbCloudInfrastructure.Services
|
|
{
|
|
public class EventService : IEventService
|
|
{
|
|
private readonly ITelemetryService telemetryService;
|
|
private readonly CacheTable<Event> cacheEvents;
|
|
|
|
public EventService(IAsbCloudDbContext db, CacheDb cacheDb, ITelemetryService telemetryService)
|
|
{
|
|
this.telemetryService = telemetryService;
|
|
cacheEvents = cacheDb.GetCachedTable<Event>((AsbCloudDbContext)db);
|
|
}
|
|
|
|
public void Upsert(string uid, IEnumerable<EventDto> dtos)
|
|
{
|
|
if (!dtos.Any())
|
|
return;
|
|
|
|
var telemetryId = telemetryService.GetOrCreateTemetryIdByUid(uid);
|
|
|
|
var entities = dtos.Select(dto => new Event
|
|
{
|
|
IdEvent = dto.Id,
|
|
IdTelemetry = telemetryId,
|
|
IdCategory = dto.IdCategory,
|
|
MessageTemplate = dto.Message
|
|
});
|
|
cacheEvents.Upsert(entities);
|
|
}
|
|
}
|
|
}
|