115 lines
3.7 KiB
C#
115 lines
3.7 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.System
|
|
{
|
|
public class SystemRepository : ISystemRepository
|
|
{
|
|
#region Private Fields
|
|
|
|
private readonly IDbContextFactory<MoonProContext> _ctxFactory;
|
|
private readonly IConfiguration _configuration;
|
|
|
|
#endregion
|
|
|
|
#region Public Constructors
|
|
|
|
public SystemRepository(IDbContextFactory<MoonProContext> ctxFactory, IConfiguration configuration)
|
|
{
|
|
_ctxFactory = ctxFactory;
|
|
_configuration = configuration;
|
|
}
|
|
|
|
#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<bool> ConfigUpdateAsync(ConfigModel updRec)
|
|
{
|
|
bool fatto = false;
|
|
ConfigModel dbResult = new();
|
|
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
|
dbResult = await dbCtx
|
|
.DbSetConfig
|
|
.Where(x => x.Chiave == updRec.Chiave)
|
|
.FirstOrDefaultAsync();
|
|
if (dbResult != null)
|
|
{
|
|
dbResult.Valore = updRec.Valore;
|
|
fatto = await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> EvListInsertAsync(EventListModel newRec)
|
|
{
|
|
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
|
_ = await dbCtx
|
|
.DbSetEvList
|
|
.AddAsync(newRec);
|
|
return await dbCtx.SaveChangesAsync() > 0;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<bool> ForceDbMaintAsync(bool doExec, bool doUpdStat, bool doSave, int minPgCnt, int minAvgFrag, int maxAvgFragReb)
|
|
{
|
|
await using var dbCtx = new MoonProAdminContext(_configuration);
|
|
|
|
_ = await dbCtx
|
|
.Database
|
|
.ExecuteSqlRawAsync("EXEC man.stp_Utility_Maintanance");
|
|
return true;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<LinkMenuModel>> ListLinkAllAsync()
|
|
{
|
|
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
|
return await dbCtx
|
|
.DbSetLinkMenu
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.Ordine)
|
|
.ToListAsync();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<LinkMenuModel>> ListLinkFiltAsync(string tipoLink)
|
|
{
|
|
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
|
return await dbCtx
|
|
.DbSetLinkMenu
|
|
.Where(x => x.TipoLink == tipoLink)
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.Ordine)
|
|
.ToListAsync();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public Task<List<LinkMenuModel>> ElencoLinkAsync()
|
|
{
|
|
return ListLinkFiltAsync("SpecLink");
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|