9055eaf73c
- aggiunta pagina operatori - completato fix
130 lines
4.6 KiB
C#
130 lines
4.6 KiB
C#
using Microsoft.Data.SqlClient;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using MP.Data.DbModels;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Data.Repository.Dossier
|
|
{
|
|
public class DossierRepository : IDossierRepository
|
|
{
|
|
#region Public Constructors
|
|
|
|
public DossierRepository(
|
|
IConfiguration configuration,
|
|
IDbContextFactory<MoonPro_FluxContext> ctxFactoryFL)
|
|
{
|
|
_configuration = configuration;
|
|
_ctxFactoryFL = ctxFactoryFL;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<string>> ArticleWithDossierAsync()
|
|
{
|
|
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
|
return await dbCtx
|
|
.DbSetDossiers
|
|
.AsNoTracking()
|
|
.Select(i => i.CodArticolo)
|
|
.Distinct()
|
|
.ToListAsync();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> DossiersDeleteRecordAsync(DossierModel currRec)
|
|
{
|
|
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
|
var currVal = await dbCtx
|
|
.DbSetDossiers
|
|
.Where(x => x.IdxDossier == currRec.IdxDossier)
|
|
.FirstOrDefaultAsync();
|
|
dbCtx
|
|
.DbSetDossiers
|
|
.Remove(currVal);
|
|
|
|
return await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<DossierModel>> DossiersGetLastFiltAsync(string IdxMacchina, string CodArticolo, DateTime DtStart, DateTime DtEnd, int MaxRec)
|
|
{
|
|
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
|
return await dbCtx
|
|
.DbSetDossiers
|
|
.AsNoTracking()
|
|
.Where(x => (IdxMacchina == "*" || x.IdxMacchina == IdxMacchina) && (CodArticolo == "*" || x.CodArticolo == CodArticolo) && (x.DtRif >= DtStart && x.DtRif <= DtEnd))
|
|
.Include(m => m.MachineNav)
|
|
.Include(a => a.ArticoloNav)
|
|
.OrderByDescending(x => x.DtRif)
|
|
.Take(MaxRec)
|
|
.ToListAsync();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> DossiersInsertAsync(DossierModel newRec)
|
|
{
|
|
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
|
await dbCtx
|
|
.DbSetDossiers
|
|
.AddAsync(newRec);
|
|
return await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> DossiersTakeParamsSnapshotLastAsync(string idxMacchina, DateTime dtMin, DateTime dtMax)
|
|
{
|
|
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
|
var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMacchina);
|
|
var pDtMin = new SqlParameter("@DtMin", dtMin);
|
|
var pDtMax = new SqlParameter("@DtMax", dtMax);
|
|
|
|
var dbResult = await dbCtx
|
|
.Database
|
|
.ExecuteSqlRawAsync("EXEC stp_FL_TakeSnapshotLast @IdxMacchina,@DtMin,@DtMax", pIdxMacchina, pDtMin, pDtMax);
|
|
return dbResult != 0;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> DossiersUpdateValoreAsync(DossierModel editRec)
|
|
{
|
|
await using var dbCtx = await _ctxFactoryFL.CreateDbContextAsync();
|
|
var currRec = await dbCtx
|
|
.DbSetDossiers
|
|
.Where(x => x.IdxDossier == editRec.IdxDossier)
|
|
.FirstOrDefaultAsync();
|
|
if (currRec != null)
|
|
{
|
|
currRec.Valore = editRec.Valore;
|
|
dbCtx.Entry(currRec).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
await dbCtx
|
|
.DbSetDossiers
|
|
.AddAsync(editRec);
|
|
}
|
|
return await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Protected Fields
|
|
|
|
protected readonly IDbContextFactory<MoonPro_FluxContext> _ctxFactoryFL;
|
|
|
|
#endregion Protected Fields
|
|
|
|
#region Private Fields
|
|
|
|
private readonly IConfiguration _configuration;
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |