101 lines
3.3 KiB
C#
101 lines
3.3 KiB
C#
using Microsoft.Data.SqlClient;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using MP.Data.DbModels;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Data.Repository.MpMon
|
|
{
|
|
public class MpMonRepository : IMpMonRepository
|
|
{
|
|
#region Private Fields
|
|
|
|
private readonly IDbContextFactory<MoonProContext> _ctxFactory;
|
|
|
|
#endregion
|
|
|
|
#region Public Constructors
|
|
|
|
public MpMonRepository(IDbContextFactory<MoonProContext> ctxFactory)
|
|
{
|
|
_ctxFactory = ctxFactory;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public Methods
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<ConfigModel>> ConfigGetAllAsync()
|
|
{
|
|
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
|
return await dbCtx
|
|
.DbSetConfig
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.Chiave)
|
|
.ToListAsync() ?? new();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<MacchineModel>> MacchineGetAllAsync()
|
|
{
|
|
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
|
return await dbCtx
|
|
.DbSetMacchine
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.IdxMacchina)
|
|
.ToListAsync() ?? new();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<MacchineModel>> MacchineGetFiltAsync(string codGruppo)
|
|
{
|
|
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
|
List<MacchineModel> dbResult;
|
|
if (codGruppo == "*")
|
|
{
|
|
dbResult = await dbCtx
|
|
.DbSetMacchine
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.IdxMacchina)
|
|
.ToListAsync();
|
|
}
|
|
else
|
|
{
|
|
dbResult = await dbCtx
|
|
.DbSetGrp2Macc
|
|
.Where(g => g.CodGruppo == codGruppo)
|
|
.Join(dbCtx.DbSetMacchine,
|
|
g => g.IdxMacchina,
|
|
m => m.IdxMacchina,
|
|
(g, m) => m
|
|
)
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.IdxMacchina)
|
|
.ToListAsync();
|
|
}
|
|
dbResult = dbResult
|
|
.Where(x => !string.IsNullOrEmpty(x.locazione))
|
|
.OrderBy(x => x.locazione).ToList();
|
|
return dbResult;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<MappaStatoExplModel>> MseGetAllAsync(int maxAge = 2000)
|
|
{
|
|
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
|
var maxAgeSec = new SqlParameter("@maxAgeSec", maxAge);
|
|
var dbResult = await dbCtx
|
|
.DbSetMSE
|
|
.FromSqlRaw("EXEC stp_MSE_getData @maxAgeSec", maxAgeSec)
|
|
.AsNoTracking()
|
|
.ToListAsync();
|
|
return dbResult;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|