9055eaf73c
- aggiunta pagina operatori - completato fix
82 lines
2.6 KiB
C#
82 lines
2.6 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using MP.Data.DbModels;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace MP.Data.Repository.MpVoc
|
|
{
|
|
public class MpVocRepository : IMpVocRepository
|
|
{
|
|
#region Public Constructors
|
|
|
|
public MpVocRepository(IDbContextFactory<MoonPro_VocContext> ctxFactory)
|
|
{
|
|
_ctxFactory = ctxFactory;
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
#if false
|
|
/// <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();
|
|
}
|
|
#endif
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<LingueModel>> LingueGetAllAsync()
|
|
{
|
|
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
|
return await dbCtx
|
|
.DbSetLilngue
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.Lingua)
|
|
.ToListAsync() ?? new();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<List<VocabolarioModel>> VocabolarioGetAllAsync()
|
|
{
|
|
await using var dbCtx = await _ctxFactory.CreateDbContextAsync();
|
|
return await dbCtx
|
|
.DbSetVocabolario
|
|
.AsNoTracking()
|
|
.OrderBy(x => x.Lemma)
|
|
.ToListAsync() ?? new();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public Dictionary<string, string> VocabolarioGetLang(string lingua)
|
|
{
|
|
using var dbCtx = _ctxFactory.CreateDbContextAsync().GetAwaiter().GetResult();
|
|
var rawList = dbCtx
|
|
.DbSetVocabolario
|
|
.AsNoTracking()
|
|
.Where(x => x.Lingua.ToLower() == lingua.ToLower())
|
|
.OrderBy(x => x.Lemma)
|
|
.ToList();
|
|
// Proietto in dizionario
|
|
return rawList
|
|
.DistinctBy(t => t.Lemma, StringComparer.OrdinalIgnoreCase)
|
|
.ToDictionary(t => t.Lemma, t => t.Traduzione, StringComparer.OrdinalIgnoreCase);
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private readonly IDbContextFactory<MoonPro_VocContext> _ctxFactory;
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |