using AsbCloudApp.Data; using AsbCloudApp.Repositories; using AsbCloudDb.Model; using Mapster; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace AsbCloudInfrastructure.Repository { public class DataSaubStatRepository : IDataSaubStatRepository { private readonly IAsbCloudDbContext db; public DataSaubStatRepository(IAsbCloudDbContext dbContext) { db = dbContext; } public async Task> GetLastDatesAsync(int[] idTelemetries, CancellationToken token) { var stats = await db.Set() .Where(s => idTelemetries.Contains(s.IdTelemetry)) .GroupBy(s => s.IdTelemetry, (key, group) => new DataSaubStatDto() { IdTelemetry = key, DateEnd = group.Max(s => s.DateEnd) }) .ToArrayAsync(token); return stats; } public async Task InsertRangeAsync(IEnumerable dataSaubStats, CancellationToken token) { var entities = dataSaubStats.Select(data => data.Adapt()); db.Set().AddRange(entities); return await db.SaveChangesAsync(token); } } }