2024-11-25 13:49:07 +05:00
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Persistence.Database.Entity;
|
|
|
|
|
using Persistence.Models;
|
|
|
|
|
using Persistence.Repositories;
|
|
|
|
|
|
|
|
|
|
namespace Persistence.Repository.Repositories
|
|
|
|
|
{
|
|
|
|
|
public class TechMessagesRepository : ITechMessagesRepository
|
|
|
|
|
{
|
|
|
|
|
private DbContext db;
|
|
|
|
|
public TechMessagesRepository(DbContext db)
|
|
|
|
|
{
|
|
|
|
|
this.db = db;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual IQueryable<TechMessage> GetQueryReadOnly() => db.Set<TechMessage>();
|
|
|
|
|
|
2024-11-26 10:23:48 +05:00
|
|
|
|
public async Task<PaginationContainer<TechMessageDto>> GetPage(RequestDto request, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var query = GetQueryReadOnly();
|
|
|
|
|
var entities = await query
|
|
|
|
|
.SortBy(request.SortSettings)
|
|
|
|
|
.Skip(request.Skip)
|
|
|
|
|
.Take(request.Take)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
var dto = new PaginationContainer<TechMessageDto>()
|
|
|
|
|
{
|
|
|
|
|
Skip = request.Skip,
|
|
|
|
|
Take = request.Take,
|
|
|
|
|
Count = entities.Count,
|
|
|
|
|
Items = entities.Select(e => e.Adapt<TechMessageDto>())
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return dto;
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-25 13:49:07 +05:00
|
|
|
|
public async Task<int> GetStatistics(int importantId, string autoDrillingSystem, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var query = GetQueryReadOnly();
|
|
|
|
|
var count = await query
|
|
|
|
|
.Where(e => e.ImportantId == importantId && e.AutoDrillingSystem == autoDrillingSystem)
|
|
|
|
|
.CountAsync();
|
|
|
|
|
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<string>> GetSystems(CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var query = GetQueryReadOnly();
|
|
|
|
|
var entities = await query
|
|
|
|
|
.Select(e => e.AutoDrillingSystem ?? string.Empty)
|
|
|
|
|
.Distinct()
|
|
|
|
|
.ToArrayAsync(token);
|
|
|
|
|
var dtos = entities.Order();
|
|
|
|
|
|
|
|
|
|
return dtos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<int> InsertRange(IEnumerable<TechMessageDto> dtos, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var entities = dtos.Select(d => d.Adapt<TechMessage>());
|
|
|
|
|
|
|
|
|
|
await db.Set<TechMessage>().AddRangeAsync(entities, token);
|
|
|
|
|
var result = await db.SaveChangesAsync(token);
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|