Inizia code assisted review (non compila...)
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
using MP.Data.DbModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MP.Data.Repository.System
|
||||
{
|
||||
public interface ISystemRepository
|
||||
{
|
||||
Task<List<ConfigModel>> ConfigGetAllAsync();
|
||||
|
||||
Task<bool> ConfigUpdateAsync(ConfigModel updRec);
|
||||
|
||||
Task<bool> EvListInsertAsync(EventListModel newRec);
|
||||
|
||||
Task<bool> ForceDbMaintAsync(bool doExec, bool doUpdStat, bool doSave, int minPgCnt, int minAvgFrag, int maxAvgFragReb);
|
||||
|
||||
Task<List<LinkMenuModel>> ListLinkAllAsync();
|
||||
|
||||
Task<List<LinkMenuModel>> ListLinkFiltAsync(string tipoLink);
|
||||
|
||||
Task<List<LinkMenuModel>> ElencoLinkAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user