Vocabolario:
- Fix creazione tab + stored - modifica metodo upsert
This commit is contained in:
@@ -3,8 +3,11 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using NLog;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Data;
|
||||
using WebDoorCreator.Data.DbModels;
|
||||
using WebDoorCreator.Data.DTO;
|
||||
using static WebDoorCreator.Core.Enum;
|
||||
|
||||
namespace WebDoorCreator.Data.Controllers
|
||||
{
|
||||
@@ -676,8 +679,8 @@ namespace WebDoorCreator.Data.Controllers
|
||||
try
|
||||
{
|
||||
dbCtx
|
||||
.Database
|
||||
.ExecuteSqlRaw("EXEC man.[stp_TruncTables]");
|
||||
.Database
|
||||
.ExecuteSqlRaw("EXEC man.[stp_TruncTables]");
|
||||
|
||||
dbResult = true;
|
||||
}
|
||||
@@ -836,55 +839,34 @@ namespace WebDoorCreator.Data.Controllers
|
||||
/// <summary>
|
||||
/// Aggiunta di un nuovo set di lemmi
|
||||
/// </summary>
|
||||
/// <param name="newVocLemma"></param>
|
||||
/// <param name="listNewTerms"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> VocLemmaInsert(List<VocabularyModel> newVocLemma)
|
||||
public async Task<bool> VocLemmaInsert(List<VocabularyTempModel> listNewTerms)
|
||||
{
|
||||
bool fatto = false;
|
||||
List<VocabularyModel> list2Ins = new List<VocabularyModel>();
|
||||
List<VocabularyModel> list2Upd = new List<VocabularyModel>();
|
||||
|
||||
using (WDCDataContext localDbCtx = new WDCDataContext(_configuration))
|
||||
{
|
||||
try
|
||||
{
|
||||
var lisKey = localDbCtx
|
||||
.DbSetVocabulary
|
||||
.ToList();
|
||||
|
||||
foreach (var item in newVocLemma)
|
||||
{
|
||||
var trovato = lisKey.Where(x => x.Lingua == item.Lingua && x.Lemma == item.Lemma).FirstOrDefault();
|
||||
|
||||
if (trovato == null)
|
||||
{
|
||||
list2Ins.Add(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (trovato.Traduzione != item.Traduzione)
|
||||
{
|
||||
list2Upd.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//aggiungo i mancanti
|
||||
// stored di reset vocabolario
|
||||
var storedRes = localDbCtx
|
||||
.Database
|
||||
.ExecuteSqlRaw("exec dbo.stp_Voc_Prepare");
|
||||
|
||||
// import massivo dati in tab temp
|
||||
localDbCtx
|
||||
.DbSetVocabulary
|
||||
.AddRange(list2Ins);
|
||||
.DbSetVocabularyTemp
|
||||
.AddRange(listNewTerms);
|
||||
|
||||
localDbCtx.SaveChanges();
|
||||
|
||||
|
||||
// stored di merge dati in vocabolario
|
||||
storedRes = localDbCtx
|
||||
.Database
|
||||
.ExecuteSqlRaw("exec dbo.stp_Voc_Import");
|
||||
|
||||
foreach (var item in list2Upd)
|
||||
{
|
||||
var trovato = newVocLemma.Where(x => x.Lingua == item.Lingua && x.Lemma == item.Lemma).FirstOrDefault();
|
||||
if (trovato != null)
|
||||
{
|
||||
trovato.Traduzione = item.Traduzione;
|
||||
localDbCtx.Entry<VocabularyModel>(trovato).State = EntityState.Modified;
|
||||
}
|
||||
}
|
||||
await localDbCtx.SaveChangesAsync();
|
||||
fatto = true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
|
||||
Reference in New Issue
Block a user